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

How do you get all of the Children on "every" children?

Hello Community! I am attempting to get the children of "every" children on a Parent.

This is the script I experimented on but didn't work lol.

local folder = game:GetService("ReplicatedStorage").Folder:GetChildren() local children = folder:GetChildren()

Thanks!

2 comments

0

The reason your script didn't work is because your variable "folder" contains all of the children inside the folder. Then, in your second variable "children", you set it to the "getchildren" of folder. It's the equivalent of: "children = Folder:GetChildren():GetChildren()"

3 answers

I think that what you are looking for is Instance:GetDescendants(). It will allow you to go through every child, and the children of that child and so forth.

3 comments

0

I provided two options because what if he does not want to include the children of any given child of the folder children

0

That's were if statements come into play.

0

If he didnt want to do that for all of the children in an array he could just use the "GetDescendants" function on that particular object in thearray instead. You don't have to explain to me how your answer is superior. Let you do you, and me do me.

local folder = game:GetService("ReplicatedStorage").Folder:GetDecendants()

or

local folder = game:GetService("ReplicatedStorage").Folder:GetChildren() 
local children = {}
for i, v in pairs(folder) do
	table.insert(children, folder[i]:GetChildren())
end

But the first one will include any of the folder's children's children. Use the output at all times when scripting, so you will get more detailed info on the error. Just by the code you used, I can guess your error was something like Attempt to call a nil value

local folder = game:GetService("ReplicatedStorage").Folder

for _, v in pairs(folder:GetDescendants()) do
    print(v.Name) -- v equals all of the children and children of children in the folder.
end

That will do it.

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