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

How can I arrange players in a certain order inside of a table?

Asked by 6 years ago

I am trying to arrange players inside of a table where 'blue' team is listed first and 'red' team is listed last. However, my script[which should work] that inserts all players in blue team first and inserts red team players last inside of a table is not working correctly. Here it is:

RunService.RenderStepped:connect(function()
    Players = {}
    for _, v in next(game.Players:GetPlayers()) do
        if v.TeamColor == BrickColor.Blue() then
            table.insert(Players, v)
        end
        if v.TeamColor == BrickColor.Red() then
            table.insert(Players, v)
        end
    end
end)

Whenever I call the table, sometimes a player in the red team is stuck in between all the players in the blue team list and it gets more confusing there.

1
Teams have a GetPlayers function that can do what you're trying to automatically. http://wiki.roblox.com/index.php?title=API:Class/Team/GetPlayers M39a9am3R 3210 — 6y
0
thank you laughablehaha 494 — 6y

Answer this question