When you first open Roblox Studio, you’ll see a window called the Explorer on the right side of your screen. It might look like a simple list at first, but it’s actually showing you something super important: the hierarchy of your entire game!
Understanding how this hierarchy works is one of the most fundamental skills in Roblox scripting. Once you get it, so many things will start making sense. Let’s break it down together!
What is the Explorer Hierarchy?
Think of the Explorer like a family tree. Every object in your Roblox game exists somewhere in this tree structure. Some objects contain other objects, and those objects might contain even more objects inside them.
In Roblox, we call this a parent-child relationship:
- A parent is an object that contains other objects inside it
- A child is an object that exists inside another object
For example, when you look at the Workspace in the Explorer, you might see a Model called “House”, and inside that Model, you might see several Parts that make up the walls, roof, and door. In this case, the Model is the parent and the Parts are its children.
Why Does This Matter?
You might be wondering, “Why can’t everything just be in one big list?” Great question! The hierarchy system is actually super helpful for several reasons:
- Organization: Grouping related objects together makes your game easier to manage. Imagine trying to find one specific brick in a game with thousands of parts!
- Scripting access: We can use the parent-child relationship to find and reference objects in our code
- Game behavior: Where you put an object affects how it behaves. Scripts only run in certain locations, and objects only appear in-game when they’re in the right place
Accessing Parents and Children in Code
Now let’s get into the scripting side of things! Every object in Roblox has a .Parent property that tells you what contains it.
local part = script.Parent
print(part.Parent.Name)
This is probably the most common line you’ll see in beginner scripts: script.Parent. This means “get the object that contains this script.” If your script is inside a Part, then script.Parent refers to that Part.
Finding Children
To go the other direction and find objects inside a parent, we use methods like FindFirstChild() or WaitForChild():
local workspace = game.Workspace
local myPart = workspace:FindFirstChild("MyPart")
if myPart then
print("Found the part!")
myPart.BrickColor = BrickColor.new("Bright red")
else
print("Part doesn't exist")
end
Notice how we’re checking if myPart then? That’s because FindFirstChild() returns nil if it can’t find the object. This prevents errors in your code!
If you’re sure an object exists (or will exist soon), you can use WaitForChild() instead:
local myPart = workspace:WaitForChild("MyPart")
print("Definitely found it!")
myPart.Transparency = 0.5
This method will pause the script and wait until the object exists. It’s really useful when objects are loading into the game.
Changing Parents
You can move objects around in the hierarchy by changing their Parent property:
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Parent = workspace -- Now it appears in the game!
This is important: when you create new objects with Instance.new(), they don’t appear anywhere until you set their Parent. Also, notice that we set all the properties before setting the Parent. This is a best practice because it’s more efficient!
A Warning About Nil
If you set an object’s Parent to nil, it removes the object from the game (but it still exists in memory):
part.Parent = nil -- Part disappears from the game
This is different from using :Destroy(), which completely removes the object and frees up memory.
Common Hierarchy Locations
Here are some important containers you’ll work with constantly:
- Workspace: Where all visible game objects go (parts, models, etc.)
- ReplicatedStorage: For objects that both the server and clients need to access
- ServerScriptService: Where you put scripts that only run on the server
- StarterPlayer: Contains folders for scripts that run for each player
Recap
You’ve just learned one of the most essential concepts in Roblox development! Remember: the Explorer shows a hierarchy where objects can contain other objects. Parents hold children, and you can access these relationships using .Parent, FindFirstChild(), and WaitForChild() in your code.
Understanding this hierarchy is crucial because nearly every script you write will need to find and reference objects in your game world.
What’s next? Now that you understand the hierarchy, you’re ready to learn about properties and methods—how to actually modify and interact with the objects you’re finding. Keep up the great work!