Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you create random teams?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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
0
Please consider this as "Correct Answer" and vote up if you feel that I have helped you. fahmisack123 385 — 10y
Ad

Answer this question