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

How do I make this spread the teams equally?

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

✓ Accepted answer

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

3 comments

0

Sorry its just a small part of the script. Those ends are for other things

0

Ok, but did it work?

0

The val = val + 1 and the else were essencial, I think.

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

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