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

Is it possible to count children in a script?

Asked by
NecoBoss 194
10 years ago

How would you use a script to count children in let's say Workspace?

2 answers

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Of course.

We can get the list of children of the workspace simply:

local children = workspace:GetChildren();

Since children is a table, we can get its length using the # operator:

local children = workspace:GetChildren();
local numberOfChildren = #children;
-- How many things are children,
-- the length of the list of children
Ad
Log in to vote
0
Answered by
Vathriel 510 Moderation Voter
10 years ago

Well, you'd use getchildren, which returns a table.

NumberOfChildren = #game.Workspace:GetChildren()

Answer this question