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

I need assistance with dividing teams, how do I divide for the Red, Blue, Green teams?

	if Round == 'RGB' then
			local NewRound = RoundCarrier.RGB:Clone()
			NewRound.Parent = RoundFolder
				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") or BrickColor.new("Bright green"))
    			switch = not switch
				end

There is nothing wrong with the code, except for the fact that the green team is completely neglected when the script runs.

How would I go about fixing this so that players are added to all three teams?

1 comment

0

Move green to the start of the script then it won't be neglected

1 answer

✓ Accepted answer

That's a clever way of dividing between two teams! Sadly, it won't work with 3 teams, because a bool has only two cases. To make it work, I'd use an if/elseif ladder and a wrapping counter. Simpler, easier to understand, and expandable to as many teams as you want.

if Round == 'RGB' then
        local NewRound = RoundCarrier.RGB:Clone()
        NewRound.Parent = RoundFolder
        local ctr = 0
        for i,v in pairs(game.Players:GetPlayers()) do 
		ctr = ctr+1
		if ctr > 3 then ctr = 1 end --Wrap to 1
		if ctr == 1 then
			v.TeamColor = BrickColor.new("Bright red")
		elseif ctr == 2 then
			v.TeamColor = BrickColor.new("Bright blue")
		elseif ctr == 3 then
			v.TeamColor =BrickColor.new("Bright green")
		end	
	end
end

All this does is count repeatedly from 1 to 3, and then sets a team based on the current number. To compact it, look into using an array.

1 comment

0

Thank you, I considering doing something like that, just wasn't sure how to go about it, again, thank you!

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