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
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)

I want this code to work in a Script, not a LocalScript. How would I make it work? [I want the code to work so that it constantly updates the count of players on each team]

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

This is the same code, but just easier to read:

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)

So, it doesn't work?

If it's not working, and you're trying to run it from a server script, I believe that RenderStepped is only able to be used in LocalScripts. Correct me if I'm wrong.

0
yes it is. So how do i run it from a server script? Tor6 0 — 10y
0
Then use .Stepped instead of .RenderStepped. Tkdriverx 514 — 10y
Ad

Answer this question