How do I reference how many players are on a team?

It’s in the title, I’m working on a game and I want to make the round end when there is 1 player left alive. the alive players go onto the Playing team and if you die you get sent to the Lobby team. How do i reference how many players are on the playing team?

1 Like

Calling the GetPlayers function on a team returns a table of all the players on that team. You can get the number of elements in that table by using a pound sign.

local numPlayers = #game.Teams.Playing:GetPlayers()
4 Likes

would it be possible to get the last player on Playing teams username? for instance a text label will say “Rinpix Has Won The Game.”

2 Likes

You’d just have to index the first element in the table:

local players = game.Teams.Playing:GetPlayers()
local winner = players[1]
local numPlayers = #players
1 Like

sorry for still going on, but how would i give the winner a stat

1 Like

You should have a table, storing there the winner and eventually look for him on game.Players, and then award him.

1 Like