Lesson 6 of 7

The data model: every service and where things live

Roblox's data model explained through Beacon Yard: instances, services and GetService, which container runs which script, where ModuleScripts run, and how default.project.json maps folders onto the tree.

Concept lesson, about 65 minutes, 8 steps

By the end you can

  • Explain instances, services and GetService, and tell containers you fill from services you call
  • Say which side runs a Script, a LocalScript and a ModuleScript in each container
  • Map every entry in Beacon Yard's default.project.json to the instance it creates

Before this: The Studio tour: panels, camera, shortcuts

Step 1 of 8

Looking in the wrong drawer

A new teammate wants to change how many coins a pad pays. They open Workspace, expand everything, and find parts but no code. They decide the game must be broken.

The coin code is right there, just not in Workspace. It is ServerScriptService.Server.CoinService, a module inside the server Script. The tree Explorer shows is the data model: every object in the place, and where it sits decides what it does1. This lesson walks the whole tree on m03-coins-count.

Roblox Studio
Studio's Explorer in edit mode on a later Beacon Yard build with the service roots expanded: ReplicatedFirst with Loading, ReplicatedStorage with Assets, Shared and GameTests, and ServerScriptService with Server and its modules.

Select a numbered pin, or a row below, to read what it marks.

The script homes in edit mode. This capture is from a later build, so it also shows Loading and Assets, which arrive after m03-coins-count; at m03 you see Shared, Server and Client.

Choose one

Where is Beacon Yard's CoinService in the data model?

Where is Beacon Yard's CoinService in the data model?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 2 of 8

Instances and services

Every object in the tree is an instanceInstanceAny object in a Roblox game: a part, a script, a folder, a sound.Think of it as a folder or file in a filing cabinet.: a Part, a Script, a Folder, a RemoteEvent. Each has a class, a Name, a Parent and properties. Instance.new("Part") makes one, but it is not in the world until you set its Parent.

The top-level objects are servicesServiceA built-in top-level object that owns one area of the engine, such as Players or DataStoreService.Think of it as a department with one front door.. You never create them; you ask for them by name2:

luau
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

Services come in two kinds: containers you put objects inside, and services whose methods and events you call. Players is a good example of the second kind: the engine adds a Player object when someone joins, and your code connects to Players.PlayerAdded instead of creating a Player itself.

Reference Every core service at a glance
ServiceKindWhat lives there or what it does
WorkspaceContainerThe simulated 3D world (parts, models, characters, terrain), replicated to clients
LightingContainerTime of day (ClockTime), atmosphere, shadows and sky
ReplicatedFirstContainerClient loading scripts and assets sent to players before everything else
ReplicatedStorageContainerShared modules, remotes and templates both server and clients can read
ServerScriptServiceContainerServer Scripts and modules; never replicated to clients
ServerStorageContainerServer-only templates and data; never replicated to clients
StarterPlayerContainerHolds StarterPlayerScripts (copied once per player) and StarterCharacterScripts (copied on every spawn)
StarterPackContainerTools copied into each player's backpack when their character spawns
StarterGuiContainerScreenGuis copied into each player's PlayerGui
SoundServiceContainerGlobal audio settings and shared sound objects
MaterialServiceContainerCustom MaterialVariant overrides for built-in materials
PlayersCallTracks connected Player objects (PlayerAdded, PlayerRemoving)
DataStoreServiceCallServer-only persistent storage across sessions
CollectionServiceCallQueries instances by tag (GetTagged, AddTag)
RunServiceCallFrame events (Heartbeat, RenderStepped) and IsServer() / IsClient()
TweenServiceCallSmoothly animates properties over time
MarketplaceServiceCallPasses, developer products and purchase receipts
Both sidesServices is departments with one front door.
In the pictureIn Roblox
A departmentA service such as Players, or a game service such as CoinService
The one front doorgame:GetService(name), or require of the service module
Asking at the deskCalling the service's functions

See the whole analogy cast

Services are the departments of one company. Each has one front door, game:GetService("Name"), and you never open a second branch of the same department.

Think of it as Departments with one front door

Match the pairs

Match each service to how Beacon Yard uses it.

Link to this step · This confused me

Step 3 of 8

Who runs which script

Where a script sits decides whether it runs, and on which side3:

  • A Script with the default Legacy run context runs on the server, and only from server containers such as ServerScriptService or Workspace.
  • A LocalScript runs on a client, from containers copied to the player: StarterPlayerScripts, StarterCharacterScripts, StarterGui and StarterPack, plus ReplicatedFirst for loading screens.
  • A ModuleScript does not run by itself. It runs when something requires it, on the side that required it, and each side gets its own copy.

That last point is why Config lives in ReplicatedStorage.Shared. The server requires it and gets a table; each client requires it and gets its own table with the same numbers. They do not share one table across the network, which is fine, because Config holds constants, not the live coin count.

Luau
Ctrl Enter runs the cell. Checked against the expected output
Choose one

A ModuleScript in ReplicatedStorage calls DataStoreService:GetDataStore when it is required. The HUD's LocalScript requires it. What happens?

A ModuleScript in ReplicatedStorage calls DataStoreService:GetDataStore when it is required. The HUD's LocalScript requires it. What happens?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 4 of 8

The project file is the map

Beacon Yard never drags scripts around in Explorer. default.project.json says which disk folder becomes which instance, and Rojo builds the tree from it. At m03-coins-count it maps Shared, GameTests, Server, Client and Workspace. Here is how the same map looks by m06-drone-wrench, once loading screens, mesh assets and chat are added too:

    "ReplicatedFirst": {
      "Loading": {
        "$path": "src/loading"
      }
    },
    "ReplicatedStorage": {
      "Shared": {
        "$path": "src/shared"
      },
      "Assets": {
        "$path": "assets/roblox"
      },
      "GameTests": {
        "$path": "tests",
        "challenges": {
          "$path": "challenges"
        }
      }
    },
    "ServerScriptService": {
      "Server": {
        "$path": "src/server"
      }
    },
    "TextChatService": {
      "$className": "TextChatService",
      "$properties": {
        "ChatVersion": "TextChatService"
      }
    },
    "StarterPlayer": {
      "StarterPlayerScripts": {
        "Client": {
          "$path": "src/client"
        }
      }
    },
    "Lighting": {
  • src/loading becomes ReplicatedFirst.Loading, a LocalScript that shows the loading screen first (added after m03).
  • src/shared becomes ReplicatedStorage.Shared, modules both sides can require.
  • assets/roblox becomes ReplicatedStorage.Assets, mesh templates synced from disk (added after m03).
  • tests becomes ReplicatedStorage.GameTests, and challenges its child.
  • src/server becomes ServerScriptService.Server: one Script from init.server.luau, with every other file as a child ModuleScript.
  • TextChatService sets ChatVersion to TextChatService, and src/client becomes StarterPlayer.StarterPlayerScripts.Client, a LocalScript copied to each player.

The same file also sets properties that are not folders at all: Workspace.Gravity 196.2 (from m00), and later Lighting.ClockTime 17.4 and Brightness 2.6. If you only read src/, you miss those settings.

Expanding each script home in Explorer, then pressing Play to watch the tree come alive.

Transcript
  1. 0:01 ReplicatedFirst holds the loading screen.
  2. 0:05 Shared is the folder both the server and the client can require.
  3. 0:10 The server entry is one Script. The other files are child modules.
  4. 0:18 The client entry lives under StarterPlayerScripts.
  5. 0:23 Play adds Yard. The project file did not store that folder.
Match the pairs

Match each disk path to the instance Rojo makes from it.

Link to this step · This confused me

Step 5 of 8

Finding a sibling module

Because Rojo turns src/server into one Script with children, the server entry finds its modules with require(script.CoinService). script.Parent is ServerScriptService, the service, not the folder of modules, so script.Parent.CoinService finds nothing. Inside a module the rule flips: a module's siblings are script.Parent.X, because its parent is the Server Script.

Shared code is reached through its service instead: ReplicatedStorage:WaitForChild("Shared"), because Config is not a child of the server Script.

Where the client's entry script lives

OptionWhat it isWhen pros pick itTrade-offs
LocalScript in StarterPlayerScriptsCopied into each player when they join; what Beacon Yard's init.client.luau becomes.The classic pattern, and the one most existing games and tutorials use.A copy per player; one more container to remember.
Script with RunContext Client in ReplicatedStorageA Script set to run on clients, from a container clients already receive.Roblox's current recommendation for new projects: one client entry and one server entry.Newer, so fewer tutorials show it; check how your sync tool sets RunContext before you switch.
A framework such as KnitA library that boots services and controllers on each side.Teams that want a fixed structure across many games.Another layer to learn; Beacon Yard shows the plain pattern frameworks are built on.
Find the broken line

This is src/server/init.server.luau at m03. Which line fails?

This is src/server/init.server.luau at m03. Which line fails?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 6 of 8

Where the pictures break

Both sidesRemember: Services is departments with one front door.

One extra detail about the department picture: a real company has one office per department, whereas many Roblox services (such as Workspace, ReplicatedStorage and Players) exist on both the server and every client, and each side knocks on its own copy via game:GetService. (Module 2's objects lesson revisits this picture when you compare services with classes.)

The filing-cabinet picture from the Studio tour has an even sharper edge, and this lesson is where it bites hardest: in a real cabinet a folder does the same thing in any drawer, and in Studio location is behaviour.

Where does it break?“Folders in a filing cabinet” is a good picture of the instance tree. Where does it stop being true?

It breaks here. Location changes behaviour: the same part renders in Workspace, is invisible and server-only in ServerStorage, and a script runs or not depending on its container.

The true model. Every instance has one parent, and the container decides what it does: whether it renders, replicates, runs or is simulated. Moving an instance between services changes its behaviour, not just its address.

Choose one

You move a pad Part from Workspace to ServerStorage without changing its properties. Can a player still see and stand on it?

You move a pad Part from Workspace to ServerStorage without changing its properties. Can a player still see and stand on it?

Press 1 to 2 to choose, Enter to check.

Choose one

During Play you run workspace:SetAttribute("CourseCheck", 1) on the server, then press Stop. Where is CourseCheck now?

During Play you run workspace:SetAttribute("CourseCheck", 1) on the server, then press Stop. Where is CourseCheck now?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 7 of 8

Challenges

Level 1, Apprentice

Challenge

In edit mode on m03-coins-count, find the four mapped code homes and pair each with its folder on disk, without pressing Play.

Start from
m03-coins-count, Rojo connected, Play stopped

Done means

  • You found ReplicatedStorage.Shared, ReplicatedStorage.GameTests, ServerScriptService.Server and StarterPlayerScripts.Client
  • You named the disk folder each one came from

Meet the criteria above, then record your own result. No test grades this check.

Level 2, Builder

Challenge

Set a runtime attribute from the server command bar during Play, find it in Properties, press Stop and confirm it is gone.

Start from
The game at milestone m03 (download)

Done means

  • CourseCheck was visible on Workspace during Play
  • It was gone after Stop, and the synced scripts were still there

Meet the criteria above, then record your own result. No test grades this check.

Choose one

Can ReplicatedStorage have a Folder named Config while ReplicatedStorage.Shared has a ModuleScript named Config?

Can ReplicatedStorage have a Folder named Config while ReplicatedStorage.Shared has a ModuleScript named Config?

Press 1 to 4 to choose, Enter to check.

Level 3, Professional

Challenge

Add an empty Config folder next to Shared through the project file. To get a pass code, sync your change on m14-ship, press Play and run this in the server command bar:

luau
game.ServerScriptService.RunGameTests:Invoke("data-model")
Start from
The game at milestone m03 (download)
Grade it
To grade work from an earlier milestone, apply your challenge changes to a checkout based on m14-ship, which includes the Course Runner. In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("data-model") in the server command bar. Copy the pass code from Output.

Done means

  • default.project.json maps a Folder named Config directly under ReplicatedStorage
  • ReplicatedStorage.Shared.Config is still the ModuleScript

The Course Runner prints this code when the test passes.

Link to this step · This confused me

Step 8 of 8

Recap

Recap

  1. Everything is an instance in one tree; services are fetched with game:GetService, some to fill and some to call.
  2. Scripts run on the server from server containers, LocalScripts on clients from Starter containers, and a ModuleScript runs on whichever side requires it, with its own copy.
  3. default.project.json maps src/server, src/client, src/shared and tests onto the tree, and sets place properties such as Workspace.Gravity.

Services is departments with one front door, until there is exactly one of each department, fetched by name. When you need many of something, such as fifty drones, a department is the wrong shape and you want a class or plain records.

The instance tree is folders in a filing cabinet, until location changes behaviour: the same part renders in Workspace, is invisible and server-only in ServerStorage, and a script runs or not depending on its container.

Next Playtesting: Play, Run, Team Test, server and client views

Link to this step · This confused me