Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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!

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.

1 comment

0

I need it for each team. That is the issue I am having.

This discussion is preserved as it was. New answers, comments, and votes are closed.