Roblox objects and events, lesson 20
The data model and services
Goal: Find your way around the tree of objects in a game.
about 6 min3 practice exercises
Everything in a Roblox game is an Instance: parts, scripts, sounds, players. They are arranged in a tree that you see in Studio's Explorer window. Roblox calls this tree the data model, and its root is called game.
game
- Workspace the 3D world
- Gate a Part
- Script script.Parent is Gate
- Gate a Part
- Players who is in the server
- ReplicatedStorage shared with every client
- ServerScriptService server scripts only
Every instance has a Parent (what it is inside) and may have children (what is inside it). You walk the tree with dots:
local gate = workspace.Gate
print(gate.Name) -- Gate
print(gate.Parent.Name) -- Workspace
workspace is where everything in the 3D world lives. It is one of the services, the top-level containers that each do one job. You get any service with game:GetService:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
A few you will meet in this course:
| Service | What it holds |
|---|---|
| Workspace | The 3D world |
| Players | The people in the server |
| ServerScriptService | Server scripts |
| ReplicatedStorage | Things both the server and players' devices can see |
Inside a script, script is the script itself, so script.Parent is whatever it sits in. A script inside a coin can say local coin = script.Parent.
Try it in Studio
Optional, and the best way to make it stick.
Add a Part to Workspace, rename it Gate, put a Script inside it and print script.Parent.Name.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.