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

How do you divide teams evenly? [closed]

Asked by 10 years ago

This question already has an answer here:

How do I make this spread the teams equally?

How do you divide team red, and blue evenly with players? Can somebody give me an example in code, and explain what each part of code does?

Marked as Duplicate by User#2

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
Tesouro 407 Moderation Voter
10 years ago

Answered it here: How do I make this spread the teams equally?

rval = 0 --  a value to count players in red team
bval = 0 -- in blue team
for i, player in pairs(game.Players:GetPlayers()) do -- get the players
    if rval < bval then -- if one has more players than the other
        player.TeamColor = BrickColor.new("Bright red")
        rval = rval + 1 -- adding the player to the value
    elseif rval > bval then -- the inverse
        player.TeamColor=BrickColor.new("Bright blue")
        bval = bval + 1
    else -- if they're equal
        player.TeamColor = BrickColor.new("Bright red")
        rval = rval + 1
    end
end
Ad