ROBLOX Explorer uses indentation and other UI/UX interactions too, but to answer the question itself…
You can use a recursive function. While recursive functions are dangerous and could go on forever if you somehow run into a PC powerful enough to run into that forever… I’m sure you’d learn more and grow by just figuring out what could happen, what you’re filtering for and by just experimenting.
Here’s (hopefully) a working recursive function.
-- Also included documentation so that it (hopefully) plays nice with your ROBLOX studio.
-- [CreateFrameForChildren] - A function that recursively iterates over an instance's children to create and display a frame that represents each child.
--[[
A function that recursively iterates over an instance's children to create and display a frame that represents each child.<br>
<strong>instance</strong>: The instance to iterate through the children of.
]]
function CreateFrameForChildren(instance : Instance)
for index : number, child : Instance in instance:GetChildren() do
local Frame = ExampleInstance:Clone()
Frame.BE.Text = child.Name
Frame.LayoutOrder = index
Frame.Parent = Instances
Frame.Visible = true
-- This is where the recursive part can go *easily* wrong, if you have thousands of objects.
-- If the child you pass through has 50 children, and each of them have 50 children, you'd have to create, change and show 2500 (50 x 50) frames to display each child.
-- Most people won't run into that here, because most people don't have 50 children inside each child of an object with 50 children... if at all.
-- It's just a "what-if" scenario we have to think of when doing these things.
CreateFrameForChildren(child)
end
end
-- Replace parentObject with the object you want to iterate over.
CreateFrameForChildren(parentObject)
There is also another variant you can do, if you want to just display everything without regard to if it’s a child of another object or not. Instance:GetDescendants() effectively gets a family tree of every object that exists within it. So long as the Instance can see itself being the parent, grand-parent, great-grand-parent or so on of an object, it will find it with GetDescendants().
So if you want to avoid experimenting too much (which is a lot less fun in my opinion):
-- Replace [instance] with the object you want the descendants of here.
for index : number, descendant: Instance in instance:GetDescendants() do
local Frame = ExampleInstance:Clone()
Frame.BE.Text = descendant.Name
Frame.LayoutOrder = index
Frame.Parent = Instances
Frame.Visible = true
end
And when you see stuff like this:
local someVariableName : number = 235
It’s just a way for us to tell ROBLOX Studio that we expect a number to be there, so we want it to predict and show us options related to numbers when we’re typing. If you see Instance, boolean or anything like that at all, it just means we want ROBLOX to predict that we’re going to be working with that type of object.