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

how do I force one player per team?

I have six teams and the max players is six. how would I make a script that spreads the players out one team each?

1 answer

✓ Accepted answer

Hi Nickelz,

I would go about this by putting the colors for every team in a table. Then, loop through the players, make their TeamColor one from the table and, then remove that color from the table so that it can't be picked again. Something like this probably:


local teams = {
	BrickColor.new("Black");
	BrickColor.new("Really red");
	BrickColor.new("Really blue");
	BrickColor.new("Pastel Blue");
	BrickColor.new("Daisy orange");
	BrickColor.new("Shamrock");
}

local players = game:GetService("Players");

for _, player in next, players:GetPlayers() do
	local index = math.random(#teams) -- Random number from 1 to Amount of Teams.
	local team = teams[index]; -- The team color chosen on random.
	player.TeamColor = team; -- Sets player's team color to random team color
	teams.remove(teams, index); -- Removes the team color so it doesn't get repeated
end

##Well, I hope I helped and have a nice day/night.

Thanks,

Best regards,

~~ KingLoneCat

2 comments

0

Good solution!

0

Thanks.

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