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

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

Asked by 6 years ago
Edited 6 years ago

This question has been solved by the original poster.

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)

01function setTeams()
02    local firstHalf = someCode
03    local secondHalf = someOtherCode
04    for i, v in pairs(firstHalf) do
05        v.TeamColor = BrickColor.new('Bright red')
06        v:LoadCharacter()
07    end
08    for i, v in pairs(secondHalf) do
09        v.TeamColor = BrickColor.new('Bright blue')
10        v:LoadCharacter()
11    end
12end

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

How can I do it?

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

I did it. It basically uses 1 variable.

01local red = true
02for i, v in pairs(game.Players:GetChildren()) do
03    if red == true then
04        v.TeamColor = BrickColor.new('Bright red')
05        red = false
06    elseif red == false then
07        v.TeamColor = BrickColor.new('Bright blue')
08        red = true
09    end
10    v:LoadCharacter()
11end

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

Thanks everybody.

1
put [SOLVED] in your question title DeceptiveCaster 3761 — 6y
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. Rheines 661 — 6y
Ad

Answer this question