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

How can I set all players team fifty fifty at once?

Hi. I am trying to make a code. When It's executed, It makes half of the players in red team, other half of the players in blue team. How can I do it?

Here is an example. (It's example only. It isn't working)

function setTeams()
	local firstHalf = someCode
	local secondHalf = someOtherCode
	for i, v in pairs(firstHalf) do
		v.TeamColor = BrickColor.new('Bright red')
		v:LoadCharacter()
	end
	for i, v in pairs(secondHalf) do
		v.TeamColor = BrickColor.new('Bright blue')
		v:LoadCharacter()
	end
end

As I said, It's just an example. It isn't working.

How can I do it?

1 answer

I did it. It basically uses 1 variable.

local red = true
for i, v in pairs(game.Players:GetChildren()) do
	if red == true then
		v.TeamColor = BrickColor.new('Bright red')
		red = false
	elseif red == false then
		v.TeamColor = BrickColor.new('Bright blue')
		red = true
	end
	v:LoadCharacter()
end	

It simply does 1 red, 1 blue, 1 red, 1 blue .........

Thanks everybody.

2 comments

1

put [SOLVED] in your question title

0

It’s not going to be random though... GetChildren() returns an array sorted by Instances that were parented first. If you run it multiple times most players will probably be in the same team as they were previously.

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