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

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

Asked by 4 years ago

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!

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()" noammao 294 — 4y

3 answers

Log in to vote
3
Answered by
noammao 294 Moderation Voter
4 years ago

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.

0
I provided two options because what if he does not want to include the children of any given child of the folder children nc2r 117 — 4y
0
That's were if statements come into play. ForeverBrown 356 — 4y
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. noammao 294 — 4y
Ad
Log in to vote
1
Answered by
nc2r 117
4 years ago
Edited 4 years ago
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

Log in to vote
0
Answered by 4 years ago
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.

Answer this question