Getting children of children and applying changes to both?

I am attempting to make a script that will recolor an entire GUI, or more specifically every child typed as a frame or imagebutton/imagelabel.

I have already managed to get every child (using a for loop) of the specific types and color them accordingly, but some children of the GUI have their own children within them.

Tree example:
ExampleGUI
^ Frame1
–^ImageButton
^ Frame2
–^ImageLabel

Please note that I wish to keep the organization of the GUI this way.

The direct children of the GUI are colored correctly, but the children of those children are ignored.
Is there any way to construct a function to do something to every direct descendant of the GUI as well as any other children of the direct descendants?

I searched my problem on the hub, but I cannot find anything. This may be due to not knowing how to ask this question.

You could use a for in loop that goes through :GetDescendants, and then check if the instance is whatever you’re looking for by using :IsA().

2 Likes

Thanks for the reply!

Does :GetDescendants find every descendant of an object, including descendants of descendants?

:GetDescendants gets everything that has the instance as an ancestor, so yes

2 Likes

I am testing this now to see if this solves the question.

EDIT: This solved it for me, thank you!