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

Team Players Count?

Asked by
Tor6 0
10 years ago

How do I make this work in a Script, not a LocalScript?

function getPlayersOnTeam(teamColor)
local players = {}; 
for i,v in pairs(game.Players:GetPlayers()) do 
if (v.TeamColor.Name == teamColor) then 
table.insert(players, v); 
end end return players end;

game:GetService("RunService").RenderStepped:connect(function()
hn = #getPlayersOnTeam("Bright blue");
sn = #getPlayersOnTeam("Dark stone grey");
end)

p.s I want to have a count of the players!

1 answer

Log in to vote
1
Answered by
Muoshuu 580 Moderation Voter
10 years ago

Try

function GetPlayersOnTeam(Color)
    local Players={}
    for i,v in pairs(game.Players:GetChildren()) do
        if v.ClassName=="Player" then
            if v.TeamColor.Name==Color then
                table.insert(Players,v)
            end
        end
    end
    return Players
end

coroutine.wrap(function()
    while wait() do
        hn=#GetPlayersOnTeam("Bright blue")
        sn=#GetPlayersOnTeam("Dark stone grey")
    end
end)()
0
mu6666mu, does this code that you have redone constantly update the count of players on each team? or what does it do exactly? Tor6 0 — 10y
1
I've edited it to constantly get the number of players Muoshuu 580 — 10y
Ad

Answer this question