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

How to find all children of a model?

Asked by 6 years ago

i know this question is very simple but im new, how do i find all children, for example

LOL = script.Parent.DaModel.FindAllChildren --idk i just put FindAllChildren because im a noob
LOL.visibility = 1

4 answers

Log in to vote
1
Answered by 6 years ago
local Model = script.Parent.DaModel
local DaModelChildren = DaMode:GetChildren()
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
Model = game.Model
Children = Model:GetChildren()
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Edit: Looks like the rblx devs added a function find all children late last year: https://wiki.roblox.com/index.php?title=API:Class/Instance/GetDescendants The function below is the old way of doing it, just use GetDecendants.

Original Answer: Good question, this isn't an obvious thing. To get all of them, I use a recursive function, which is a fancy way of saying that it calls itself over and over.

function getAllChildren(o)
    local foundObjects = {}
    for i,v in pairs(o:GetChildren()) do
        table.insert(foundObjects, v)
        for j,k in pairs(getAllChildren(v)) do
            table.insert(foundObjects, k)
        end
    end
    return foundObjects
end

I'll just leave the code here, in case anyone else needs it.

0
Nice! I wasn't aware they'd added this functionality, but I'm glad to see the devs finally got around to it! whenallthepigsfly 541 — 6y
Log in to vote
0
Answered by 6 years ago

There is a function called :GetDescendants(). http://wiki.roblox.com/index.php?title=API:Class/Instance/GetDescendants. Since I don't support leechers I won't be fixing your code but merely providing an example.

for i,v in pairs (game.Workspace:GetDescendants()) do --Gets the descendants using iPairs
print(v) --Prints the descendants
end--ends

Please accept answer if this helped! Again, I do not like the leechers that don't accept answers.

0
ummmm, wouldnt this give me all the childrens in workspace? and, just for you to know, im not being a leecher because not accepting your answer, other people answered too SuperBeeperman 30 — 6y

Answer this question