How can assign a player a random team

Not sure if you managed since you last posted, but you just need to randomly pick a player index and iterate through the list of players and compare each player index. You then just decide which team to move them to.
Here’s an untested snippet.

using { /Fortnite.com/Devices }
using { /Verse.org/Random }

team_splitter_device := class(creative_device):

    SplitPlayers():void=

        # Retrieve all current players
        Players := GetPlayspace().GetPlayers()

        # Randomly select one player
        RandomIndex := GetRandomInt(0, Players.Length - 1)
        if:
            # Retrieve the teams
            FortTeamCollection := GetPlayspace().GetTeamCollection()
            Teams := FortTeamCollection.GetTeams()
            TeamSolo := Teams[0] # Team 1 will be the solo player
            TeamOthers := Teams[1] # Team 2 will be the others
        then:
            for(PlayerIndex -> Player:Players):
                # Move the randomly selected player to their solo team
                if(PlayerIndex = RandomIndex, FortTeamCollection.AddToTeam[Player, TeamSolo]):
                # Move the other players to the other team
                else if(FortTeamCollection.AddToTeam[Player, TeamOthers]):

Hope that answers your question!

1 Like