Getting a number of how many descendants/children are under a parent

Is there a way I can get a number based on how many children are under a parent?

Since the :GetChildren() and :GetDescendants() returns an array, you can get the length of said array by using the “#” operand.

Here’s a quick script that provides an example of how to do this:

local parent = script.Parent -- switch to the parent
local children = parent:GetChildren() -- this can be replaced by :GetDescendants()
local num = #children

print("Child count: "..num) -- if the parent had 6 children it would return: "Child count: 6"
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.