New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

how do I force one player per team?

Asked by
Nickelz 37
1 year 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 1 year 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! NowUndoThatMistake 474 — 1y
0
Thanks. KingLoneCat 2577 — 1y
Ad

Answer this question