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

How do I find the Number of Players on a Team?

Asked by 8 years ago

I have a Text Label, and I want it to display the number of players on a team. Say one team is, Team A and the other is Team B, I want it to display the number of players on each of the teams.

It should look something like this in a Text Label. "Team A: 0 Players" And that 0, would be the number of players on Team A.

2 answers

Log in to vote
1
Answered by 8 years ago

The simplest way to do this would be to loop through the players and then check the players TeamColor to tell what team the player is on. Using that you can add a number to a variable for how many players are on that team, like so:

local teamANum = 0
local teamAColor = BrickColor.new("Really red") --Change this to the team color of Team A
local teamBNum = 0
local teamBColor = BrickColor.new("Really blue") --Change this to the team color of Team B

for _, p in pairs(game.Players:GetPlayers()) do
    if p.TeamColor = teamAColor then --If the person is on team A...
        teamANum = teamANum + 1 --Add one to the total people on team A
    elseif p.TeamColor = teamBColor then --If the person is on team B...
        teamBNum = teamBNum + 1 --Add one to the total people on team B
    end
end
print(teamANum, teamBNum) --print the amount of people on team A and on team B

Hope this helped!

Ad
Log in to vote
0
Answered by 8 years ago

I'm not an expert but. As far as I tested, game.Players.NumPlayers would display the number of all the players at that time. But you want players for each team? Then I'm not sure.

game.Players.NumPlayers --Would display the numbers of players in the server.
0
I need it for each team. That is the issue I am having. SirBrayden 35 — 8y

Answer this question