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

How do I know how many people there are in a team?

Asked by 9 years ago

Hey guys,

I'm making a round based game that has Elimination. All that's missing is that I need to know how many people there are playing, I separated them in 2 teams. I went on the Wiki onto "Teams" but it did not tell me any functions/properties that give me the number of players in the team.

Can someone please help me? Thanks!

1
This is not a request site, but I will tell you it requires a for loop to go through all the players to check what team they are on. M39a9am3R 3210 — 9y

1 answer

Log in to vote
2
Answered by
W8X 95
9 years ago

Here, I created this function, I added comments so you can see how it works

function GetPlayersInTeam(Team)
local TeamColor = Team.TeamColor --Creating a variable storing the color of the team
local PlayersInTeam = 0 --Creating a variable that will store the number of players in the team
for _,Player in pairs(game.Players:GetPlayers()) do --Creating a loop that will go through all the players
if Player.TeamColor == TeamColor then --Checking if the Player's TeamColor is the same as the team's TeamColor
PlayersInTeam = PlayersInTeam + 1 --If it is, adding 1 to the variable we created earlier
end
end
return PlayersInTeam --Returning the amount of players in the team
end
Ad

Answer this question