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 5 years ago
Edited 5 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)

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

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

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.

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

Answer this question