Moving players between teams

Im working on a team selection functionality

I have two players, all players start/spawn in team 1 into the game (after pre-game)

The following code should assign player1 to team1 and player2 to team2 - it does not seem to fail, it gets to the “seems ok” print - but players are not being assigned to teams.


  setTeams(): void =
        AllTeams := GetPlayspace().GetTeamCollection().GetTeams()
        Print("AllTeams LENGTH: {AllTeams.Length}") # Prints 2 
        if:
            Team1 := AllTeams[0]
            Team2 := AllTeams[1]
            Player1 := AllPlayers[0]
            Player2 := AllPlayers[1]
        then:
            
            Print("Player1 {Localize(GetUsername(Player1))}")
            Print("Player2 {Localize(GetUsername(Player2))}")
            
            if:
                GetPlayspace().GetTeamCollection().AddToTeam[Player1, Team1]
                GetPlayspace().GetTeamCollection().AddToTeam[Player2, Team2]
                Print("Seems OK")
            else:
                Print("FAILED!")

        else:
            Print("Error setting teams")

Hmmm I dont see anything wrong with the code are you sure in your islandsettings device you have the teams option set to “Teams” and not “Free-For-All”

Where do you initialize AllPlayers? Maybe you need to update it where you initialize AllTeams