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

How do you sort only specific players into teams?

I need a script that, when run, will sort only people in a ROBLOX group into two teams. I have tried this, but the issue is that It ends up sorting unevenly.

local players = game.Players:GetPlayers()
for i = 1, #players do 
    local player = players[i]
    if player:IsInGroup(XXXXXX) then
    if i >= #players / 2 then
        player.TeamColor = BrickColor.new("Really red")
    else
        player.TeamColor = BrickColor.new("Really blue")
    end
    end
end

2 comments

0

Edited to fix code formatting.

0

You should indent your code correctly.

1 answer

local groupMembers = {}

for i, v in pairs(game.Players:GetChildren()) do
    if v:IsInGroup(XXXXXX) then
        table.insert(groupMembers, v)
    end
end

for i, v in ipairs(groupMembers) do
    if i%2 == 0 then
        v.TeamColor = BrickColor.new("Really Blue")
    else
        v.TeamColor = BrickColor.new("Really Red")
    end
end

That should do it.

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