Still have questions? Join our Discord server and get real time help.
Log in to vote

Assign only one player to a certain team?

Asked by 2 months 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
        local team = math.random(1,2)
        if team == 1 then
            player.Team = team1
        elseif team == 2 then
   = team2

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
Answered by 2 months 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))

Answer this question