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

Would this work for getting the amount of players in a team?

Asked by 6 years ago

I don't really use teams that much so I'm no very good at coding with them. I want to make it so if someone tries to join a team, but it has 25 players in it, nothing will happen. But, since I don't really know how to get the amount of players in a team, I just kind of guessed.

local b = game.Teams.Cops:GetChildren()

if b == 25 then
print("nope")
end

Would code like that work, or are the amount of players on a team stored differently?

0
Try 'if #b == 25 then' thesit123 509 — 6y
0
Nope, that didn't work. 0HappyManDudeguy0 15 — 6y
0
A table is never equivalent to a number. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

You want to use the GetPlayers() method when it comes to game.Players or a Team.

local b = game.Teams.Cops:GetPlayers() -- this method returns a table of all the players
if #b == 25 then -- the # operator gets the length of the table
    print("nope")
end

Ad

Answer this question