# How can assign a player a random team

**URL:** <https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [April 17, 2024, 3:54am UTC](https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418 "2024-04-17T03:54:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [April 17, 2024, 3:54am UTC](https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418/1 "2024-04-17T03:54:02Z")

</div>

How can I put a random player on a team and all the rest on the other?

---

<div class="post-metadata">

**Author:** ![Jimbohalo10](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jimbohalo10/32/961440_2.png) [@Jimbohalo10](https://forums.unrealengine.com/u/Jimbohalo10)\
**Post date:** [April 22, 2024, 8:24pm UTC](https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418/2 "2024-04-22T20:24:53Z")

</div>

hi @nelmi  
There is a similar problem with an answer

[issue. Setting 2 Teams of Random Players? - Programming & Scripting / Verse - Epic Developer Community Forums (unrealengine.com)](https://forums.unrealengine.com/t/decides-issue-setting-2-teams-of-random-players/1797707)

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [May 2, 2024, 6:02am UTC](https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418/3 "2024-05-02T06:02:58Z")

</div>

I read it and it doesn’t answer my issue, I’m trying to pick a player from the array and set him to team 1 (simple enough) but I don’t know how to get the other players to team two

---

<div class="post-metadata">

**Author:** ![SpyderNic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spydernic/32/933252_2.png) [@SpyderNic](https://forums.unrealengine.com/u/SpyderNic)\
**Post date:** [May 12, 2024, 6:43pm UTC](https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418/4 "2024-05-12T18:43:19Z")

</div>

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.

```auto
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!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 24, 2024, 7:51pm UTC](https://forums.unrealengine.com/t/how-can-assign-a-player-a-random-team/1807418/5 "2024-07-24T19:51:40Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
