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

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

Asked by 6 years ago

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!

0
Try changing the tPlayers inside the events to tPlayers.Value = tPlayers.Value - 1; and the local tPlayers to t1.Players. Fifkee 2017 — 6y
0
YES!!! thank you so much it works toastedtoast224 26 — 6y

2 answers

Log in to vote
3
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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")
Ad
Log in to vote
-1
Answered by 6 years ago

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

Answer this question