Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you create random teams?

I have so far tried the GetChildern() and GetPlayers() into a table, and then use math.random(1,#players) to pick a random player. Then, the script I tried to make would find what the players name was, access its teamcolor and change it to the team camo. However, I was getting nowhere, and then my internet crashed. I checked my auto-save, and it wasn't in there. So, how would you pick a random person to get teamed to the team camo?

for index, child in pairs(workspace:GetChildren()) do
    print(index, child.Name)
end

That is what I remember starting off with. Idk if that was right....

1 answer

First Off, we have to pick a random Player. To do this, we use math.random().

Players = game.Players:GetPlayers() --Gets the number of players
random = Players[math.random(1,#Players)] --Chooses a random Player

Now that we got the random player, we need to set it's TeamColor.

random.TeamColor = game.Teams.camo.TeamColor --Sets the Player's TeamColor to camo (MAKE SURE THAT camo IS SPELLED CORRECTLY)

Here's how your finished code should look like:

Players = game.Players:GetPlayers()
random = Players[math.random(1,#Players)]
random.TeamColor = game.Teams.camo.TeamColor

1 comment

0

Please consider this as "Correct Answer" and vote up if you feel that I have helped you.

This discussion is preserved as it was. New answers, comments, and votes are closed.