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

How can I find the children of children?

I am almost positive there is a property that lets you repetitively find the children of children until there is no more children (<- lol), can anybody give me the link, or write a script?

3 answers

✓ Accepted answer

The proper name for a child or child of child or &c is descendant.

To do this, we require recursion upon Children.


The observation that we make is as follows:

A descendant D of O is either

  • a child of O, or
  • a descendant of a child of O.

That is, the descendants of an object are the combination of the descendants of its children and its children.

function getDescendants(object)
	local descendants = {};
	for _, child in pairs(object:GetChildren()) do
		-- `descendants` of `object` are:
		-- children:
		table.insert(descendants, child);
		-- and descendants of children:
		local descendantsOfChild = getDescendants(child);
		for _, des in pairs( descendantsOfChild ) do
			table.insert(descendants, des);
		end
	end
	return descendants;
end

We help, not do all the work for you.

1 comment

0

your not doing the work, idk what the property is

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