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

how do I force one player per team?

Asked by
Nickelz 37
6 years ago

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

Log in to vote
2
Answered by 6 years ago

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

0
Good solution! xAtom_ik 574 — 6y
0
Thanks. KingLoneCat 2642 — 6y
Ad

Answer this question