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

How do I make this spread the teams equally?

Asked by 10 years ago

This script changes the team for each player, how do I make it go one by one, and put a player on a team, depending on the values of rval and dval?

      rval=0
      dval=0 
    for k, p in pairs(game.Players:GetPlayers()) do
if rval<=dval then
    p.TeamColor=BrickColor.new("Bright red")
elseif dval<rval then
    p.TeamColor=BrickColor.new("Bright blue")
end
end
    end
end
  end)
end)

2 answers

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

I can't see a big error, you just forgot something and it's a bit disorganized. Look:

rval = 0
dval = 0
for i, player in pairs(game.Players:GetPlayers()) do
    if rval < dval then
        player.TeamColor = BrickColor.new("Bright red")
        rval = rval + 1 -- you forgot to add the new player to the team value
    elseif rval > dval then
        player.TeamColor=BrickColor.new("Bright blue")
        dval = dval + 1 -- and here too
    else
        player.TeamColor = BrickColor.new("Bright red") -- just to start spreading them
        rval = rval + 1
    end
end
-- no use for those ends
0
Sorry its just a small part of the script. Those ends are for other things Tempestatem 884 — 10y
0
Ok, but did it work? Tesouro 407 — 10y
0
The val = val + 1 and the else were essencial, I think. Tesouro 407 — 10y
Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
local switch = true
for i,v in pairs(game.Players:GetPlayers()) do 
    v.TeamColor = (switch and BrickColor.new("Bright red") or BrickColor.new("Bright blue"))
    switch = not switch
end

Answer this question