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

How do you count children?

Asked by
NecoBoss 194
9 years ago

I am trying to figure out how to count how many children (or players) are in a players. Here is something I tried but it didn't work.

function scanclick()
if game.Players.Children < 2 then
    wait(3)
    Instance.new("Part", game.Workspace)
    Part.Anchored = true
    Part.Name = "Not Enough Players"
end
end
game.StarterGui.ScreenGui.Frame.TextButton.MouseButton1Click:connect(scanclick)

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

You'd use the NumPlayers property of Players. It can be accessed by using game.Players.NumPlayers.Value (Value may not be necessary). The way you were using the GetChildren method was improper, so I stated the easiest way.

Ad
Log in to vote
-1
Answered by 9 years ago

Theres a few ways, but this is probably the fastest way:

function scanclick()
Children = game.Players:GetChildren()
if #Children < 2 then
    --Code
end
end
game.StarterGui.ScreenGui.Frame.TextButton.MouseButton1Click:connect(scanclick)

Answer this question