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

Assign only one player to a certain team?

So I have a script that would randomly assign players to teams:

local team1 = game.Teams.Yellow
local team2 = game.Teams.Blue

    for _, player in pairs(game.Players:GetPlayers()) do
        math.randomseed(tick())
        local team = math.random(1,2)
        if team == 1 then
            player.Team = team1
        elseif team == 2 then
            player.team = team2
        end
    end

How would I change this script so that it assigns ONLY ONE player to a certain team and then assign the rest to the other team?

1 answer

✓ Accepted answer

The easiest solution would be to assign everyone to the other teams, then select the person for the single team.

The complicated solution would be to create an array of valid players to be assigned teams, like:

local others = Players:GetPlayers()
local single = table.remove(others, math.random(1, #others))

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