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

How can I find the children of children?

Asked by 10 years ago

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

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

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
Ad
Log in to vote
1
Answered by 10 years ago

Link: http://wiki.roblox.com/index.php/FindFirstChild Answer: Thing:FindFirstChild("Part", true) --True means if search children of children.

Log in to vote
-1
Answered by
Nymint 85
10 years ago

We help, not do all the work for you.

0
your not doing the work, idk what the property is tkddude2 75 — 10y

Answer this question