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

[SOLVED] Way to get the children of children?

Asked by 6 years ago
Edited 6 years ago

Explorer looks a bit like this:

- ScreenGui
    - Frame1
        - Frame2
            - Button
            - Button
        - Frame3
            - Button

I can use Frame2:GetChildren() and Frame3:GetChildren() combined to get the buttons. I need to get the buttons using only one function. Is there a way?

[EDIT]

I've found a way, you simply use i, v in pairs twice.

for index, value in pairs(Frame:GetChildren()) do
    for i, v in pairs(value:GetChildren()) do
        -- stuff
    end
end

1 answer

Log in to vote
0
Answered by 6 years ago

A better way than what you are already did is to simply make a recurse function.

function recurse(o)
    for i,v in pairs(o:GetChildren()) do
        pcall(function()
            --if statement here
            recurse(v)  
        end)
    end
end

recurse(Frame)
Ad

Answer this question