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

Assign only one player to a certain team?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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))
Ad

Answer this question