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.
Still have questions? Join our Discord server and get real time help.
Log in to vote

how do I force one player per team?

Asked by
Nickelz 37
2 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
Answered by 2 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 = {"Black");"Really red");"Really blue");"Pastel Blue");"Daisy orange");"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

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


Best regards,

~~ KingLoneCat

Good solution! NowUndoThatMistake 560 — 2y
Thanks. KingLoneCat 2617 — 2y

Answer this question