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

How to have 2 random teams?

players = game.Players:GetChildren()
		
for i,v in pairs(players) do
	print(v.Name .. " is on red team")
        v.TeamColor = BrickColor.new("Bright red")
end
for i,v in pairs(players) do
	print(v.Name .. " is on blue team")
        v.TeamColor = BrickColor.new("Bright blue")
end

How can I get this to just pick 2 random teams

1 answer

✓ Accepted answer

To make players go on to two random teams you would need to do :

players = game.Players:GetChildren()

teams = {"Bright red","Bright blue"} -- Defines the team colors, you can add more

for i,v in pairs(players) do -- Loops through the players
	        v.TeamColor = BrickColor.new(teams[math.random(1,#teams)]) -- Picks one of the brick colors out of the teams table
end

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

3 comments

0

Thanks ;)

0

ERROR< 2 people spawned on the same team, so 2 v 0 how can I fix?

0

I PM'ed you the fixed code!

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