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

Can I find how to get the number of players on a team?

I am trying to make a feature in my game where players can see how many players are on the team that they are trying to join. I am using a gui and it has a button that puts me onto the team along with a textbox that should show how many players are on the team. When I run the script it just shows 0/5 even when I join the team, and I don't get any errors. I made a number value inside the team itself and I have a function that should increase or decrease the value of it when a player is added to that team. Here's what I have in the script that is inside of the textbox

local t1 = game.Teams.T1
local tPlayers = t1.Players.Value
script.Parent.Text = tPlayers.. "/5"

t1.PlayerAdded:connect(function()

		tPlayers = tPlayers + 1
	
end)

t1.PlayerRemoved:connect(function()

		tPlayers = tPlayers - 1

end)

I hope this is enough info. If there is also a way to make the amount of players into a table then I can figure out how to get that to work as well. Thank you!

2 comments

0

Try changing the tPlayers inside the events to tPlayers.Value = tPlayers.Value - 1; and the local tPlayers to t1.Players.

0

YES!!! thank you so much it works

2 answers

✓ Accepted answer

You can use the # operator on Team:GetPlayers() to get the number of players in the team

local t1 = game:GetService("Teams").T1

print("Team T1 has", #t1:GetPlayers(), "players")

Loop thro all the players and check what team they are in.

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