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

How to get the amount of players on a team? [UNANSWERED]

Asked by 9 years ago

I need a script that waits until there is only 1 player on team Bright Blue ad then show a GUI in Game.Workspace.ScreenGui.WinnerGUI for 20 seconds, then make in invisible once again. Help is really appreciated! -Anth4598

1 answer

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
9 years ago

Loop through each player and if they're on a given team, increase a counter by one. I'd make a function like this for it.

function teamCount( team )
    local c = 0
    local team = type(team) == "string" and BrickColor.new(team) or team
    for _, plr in pairs(Game:GetService("Players"):GetPlayers()) do
        if plr.TeamColor == team then
            c = c + 1
        end
    end
    return c
end

print("#Players on Bright red: " .. teamCount("Bright red"))
-- Alternatively
print("#Players on Bright blue: " .. teamCount(BrickColor.new("Bright blue")))
Ad

Answer this question