Instance Hierarchy

From Legacy Roblox Wiki
Jump to navigationJump to search

Instance Hierarchy

The game is organized as a hierarchical tree structure.

Game
+- Workspace
+--- Base
+--- Model
+------ Part
+------ Part
+--- Player
+------ Head
+------ Torso
+------ Humanoid
+- Players
+--- Player
+------ PlayerGui
+------ Backpack
+------ StarterGear
+- StarterGui
+- StarterPack
+- Lighting

Hierarchical Access

There are various ways to access the hierarchy. The trunk is always "Game".

A shortcut "Workspace" and "workspace" refers to Game.Workspace.

You can access a child by:

parent.child
parent["child"]
parent:FindFirstChild("child")

In that last case, it is not an error if child does not exist.

You can traverse multiple level and mix them freely.

Example
Game  ( Game or game )
+- Workspace (Game.Workspace)
+--- Base (Game.Workspace.Base)
+--- Model (Game.Workspace.Model or Game.Workspace["Model"])
+------ Part (Game.Workspace.Model.Part or Game.Workspace.Model:FindFirstChild("Part"))
+------ Part (not directly addressable)
+--- Player (Game.Workspace.Player)
+------ Head (Game.Workspace.Player.Head or Game["Workspace"]:FindFirstChild("Player").Head)
+------ Torso (Game.Workspace.Player.Torso)
+------ Humanoid (Game.Workspace.Player.Humanoid or Workspace.Player.Humanoid)
+- Players (Game.Players)
+--- Player (Game.Players:FindFirstChild("Player") -- always a good idea)
+------ PlayerGui (assuming player=Game.Players.Player; player.PlayerGui)
+------ Backpack
+------ StarterGear
+- StarterGui
+- StarterPack
+- Lighting (Game.Lighting)


We can also move back up the tree if we start in the middle by way of variables.

Game
+- Workspace
+--- Base
+--- Model
+------ Part
+------ Part
+--- Player
+------ Head
+------ Torso
+------ Humanoid
+- Players
+--- Player
+------ PlayerGui
+------ Backpack
+------ StarterGear
+- StarterGui
+- StarterPack
+- Lighting
Example
b = game.Workspace.Base
part = game.Workspace.Model.Part
p = game.Players.Player
gui = game.Players.Player.PlayerGui
gui.Parent (same as game.Players.Player)
gui.Parent.Parent (same as p.Parent or game.Players)
gui.Parent.Parent.Parent (same as game)

part.Parent.Parent.Base (same as b)