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

How do you sort only specific players into teams?

Asked by 7 years ago
Edited by BlueTaslem 7 years ago

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
0
Edited to fix code formatting. BlueTaslem 18071 — 7y
0
You should indent your code correctly. BlueTaslem 18071 — 7y

1 answer

Log in to vote
-2
Answered by 7 years ago
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.

Ad

Answer this question