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

How do you find the amount of players on a team?

Asked by 10 years ago

I have absolutely no idea, so there's no code.

2 answers

Log in to vote
2
Answered by 10 years ago
for i,v in pairs(game.Players:GetChildren()) do
    local NumTeam = 0
        if v.TeamColor = BrickColor.new("Bright red") then
            NumTeam = NumTeam + 1
        end
end
script.Parent.Text = "There are "..NumTeam.." players on the Red team."
Ad
Log in to vote
-1
Answered by 10 years ago
local function GetPlayerCountFromTeam(teamname)
        local counter = 0
    local team = game.Teams:FindFirstChild(teamname)
    if team then
        local players = game.Players:GetChildren()
        for count = 1, #players do
            if players[count].TeamColor == team.TeamColor then
                counter = counter + 1
            end
            wait()
        end
    end
    return counter
end


local amount = GetPlayerCountFromTeam("YOURTEAMNAME")

Try that.

Answer this question