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

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

Asked by 6 years ago
Edited 6 years ago

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)
0
Does ``#team.getPlayers()`` not give you what you want? fredfishy 833 — 6y
0
No, like let me put my script in here so you can see what I mean. Inevitable_Judgement -10 — 6y
0
edit message and put this code in codebox. yHasteeD 1819 — 6y
0
Replace ``teamB.Players.NumPlayers`` with ``#teamB:GetPlayers()`` fredfishy 833 — 6y
View all comments (6 more)
0
We're getting closer. But now I got a different error. :) Inevitable_Judgement -10 — 6y
0
# is the length operator, gets the length of string or table, just to explain yHasteeD's answer a bit User#24403 69 — 6y
0
Ah. Thank you all for your help. Now it's working. :) Inevitable_Judgement -10 — 6y
0
Hey, I actually do have one more question for you all. So just for future reference, has "Players.NumPlayers" been deprecated? Inevitable_Judgement -10 — 6y
0
Ah. That was my thought. Lol, well I am glad they deprecated it. Inevitable_Judgement -10 — 6y

1 answer

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

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.
Ad

Answer this question