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

How does one use the Team Service to check to see if a certain number of players are on a team?

Like I know Team:GetPlayers() gets the list of players in a Team but if I wanted to make a Raid system for a group I need to be able to set the amount of players required per team. It doesn't seem that "if Team.Players.NumPlayers == Insert Value Here" works here. So, how would I go about doing this?

local teamA = game:GetService("Teams"):WaitForChild("Valkan")

local teamB = game:GetService("Teams"):WaitForChild("Raiders") -- Raiders

game.Players.PlayerAdded:Connect(function(a) 
if teamB:GetPlayers() >= teamA:GetPlayers() then 
	script.raid.Value = true 
	local m = Instance.new("Message",workspace) 
	m.Text = "RAID ON" 
	wait(6) 
	m:Destroy()
	end
end)

10 comments

0

Does #team.getPlayers() not give you what you want?

0

No, like let me put my script in here so you can see what I mean.

0

edit message and put this code in codebox.

0

Replace teamB.Players.NumPlayers with #teamB:GetPlayers()

0

We're getting closer. But now I got a different error. :)

0

is the length operator, gets the length of string or table, just to explain yHasteeD's answer a bit

0

Ah. Thank you all for your help. Now it's working. :)

0

Hey, I actually do have one more question for you all. So just for future reference, has "Players.NumPlayers" been deprecated?

0

Ah. That was my thought. Lol, well I am glad they deprecated it.

1 answer

✓ Accepted answer

You can simple add # before team:GetPlayers()

Example:

local Team = game:GetService("Teams"):WaitForChild("Blue")
print("I got " .. #Team:GetPlayers() .. " players in Blue team.")

"This simple take the length of something..."

Hope it helped :D

Solved your problems? put in title [SOLVED] or accept a answer.

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