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

How do you count children?

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

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.

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)

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