Client and server: who owns what

Learn the Roblox client-server model with Beacon Yard. Where each script runs, what replicates and what never travels back up, why the server owns coins, and how StreamingEnabled changes what a client can see.

Concept lesson, about 70 minutes, 11 steps

By the end you can

  • Say where Scripts, LocalScripts and ModuleScripts run, and which containers replicate to clients
  • Predict whether a change made on one side shows up on the other
  • Explain why coins live on the server and leaderstats are only a display copy

Before this: ModuleScripts and require, Playtesting: Play, Run, Team Test, server and client views

1Press Play, start two programs

Press Play on the m03-coins-count build and look at Output. One line comes from the client: [Beacon Yard] client started for followed by your name. Every other line in the session comes from the server. Studio has started two separate programs on your computer, and they share no memory. On a real Roblox server they would be on different continents.

local Players = game:GetService("Players")
 
print("[Beacon Yard] client started for " .. Players.LocalPlayer.Name)
Figure 1.1

Two players join a Server & Clients test of the m03 build. How many client started lines appear across all Output windows?

  1. Two, one from each player's client
  2. One, from the server
  3. One, shared by both players
  4. None; LocalScripts cannot print
Answer

Two, one from each player's client. The client script lives in StarterPlayerScripts, so Roblox copies it to every player and runs it once on each player's device. Two players, two lines.

Open this step in lesson mode · Link to this step · This confused me

2The referee and the screens at home

The serverServerThe machine Roblox runs for each copy of your game. It holds the authoritative world.Think of it as the referee with the only real scoreboard. is the machine Roblox runs for one copy of your game. It holds the real world: every part, every player's coins, the round timer. Each player's device is a clientClientOne player's device running its own copy of the game for display and input.Think of it as your screen and controller at home.: it draws the world, reads the keyboard and touch screen, and runs its own scripts1.

The server is the referee with the only real scoreboard. Players can shout requests from the stands, but only the referee changes the score.

Think of it as The referee with the only real scoreboard

Server sideRemember: The server is the referee with the only real scoreboard.

Client sideThe client is your screen and controller at home.
In the pictureIn Roblox
Your screenWhat one player's device draws
Your controllerInput that LocalScripts read and send as requests
Watching from homeSeeing a copy of the world, not the original

See the whole analogy cast

Match each Beacon Yard job to the side that does it.

  1. Adding 5 coins when a coin is touched
  2. Drawing the coin count on the HUD
  3. Reading the mouse click for a wrench swing
  4. Deciding whether the swing hit the drone
Answer

Adding 5 coins when a coin is touched: Server; Drawing the coin count on the HUD: Client; Reading the mouse click for a wrench swing: Client; Deciding whether the swing hit the drone: Server. Coins and hits change the game's state, so the server decides them. The client draws the HUD and reads input, then asks the server.

Open this step in lesson mode · Link to this step · This confused me

3Where each kind of script runs

Roblox decides where a script runs from its class and its container2:

  • A Script in ServerScriptService runs on the server.
  • A LocalScript in StarterPlayerScripts is copied to each player and runs on their client. LocalScripts in ReplicatedStorage do not run at all.
  • A ModuleScript runs wherever it is required, on the side that required it.
  • A Script with its RunContext set to Client runs on clients even from ReplicatedStorage; Beacon Yard keeps to the classic layout.

Beacon Yard's project file turns each src folder into one of these.

    "ServerScriptService": {
      "Server": {
        "$path": "src/server"
Figure 3.1

Client sideRemember: The client is your screen and controller at home.

Match each Beacon Yard source folder to where its code runs.

  1. src/server (ServerScriptService.Server)
  2. src/client (StarterPlayerScripts)
  3. src/shared (ReplicatedStorage.Shared)
  4. src/loading (ReplicatedFirst, from m06)
Answer

src/server (ServerScriptService.Server): Only on the server; src/client (StarterPlayerScripts): On every player's client; src/shared (ReplicatedStorage.Shared): Wherever it is required, so both; src/loading (ReplicatedFirst, from m06): On each client, before the rest of the game arrives. The server folder is a Script in ServerScriptService. The client folder is a LocalScript copied to each player. Shared modules run on whichever side requires them. The loading script sits in ReplicatedFirst, which clients receive first.

Open this step in lesson mode · Link to this step · This confused me

4What gets sent to clients

ReplicationReplicationThe engine copying server changes down to every client.Think of it as the live broadcast of a match. is the engine copying the server's world down to every client. It sends Workspace, ReplicatedStorage, ReplicatedFirst, Lighting, the Players service and each player's own PlayerGui and Backpack. It never sends ServerScriptService or ServerStorage, which is why server code and secret data live there: a client cannot read what it never receives.

Both sidesReplication is the live broadcast.
In the pictureIn Roblox
The match in the arenaThe server's instance tree
The broadcast feedProperty and instance changes sent to every client
The delay on the feedNetwork latency

See the whole analogy cast

Roblox Studio
Roblox Studio during Play, switched to the Server view, with Workspace.Yard selected in Explorer.

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

Figure 4.1.

The Server view during Play. The yard is built by the server and replicated to every client.

Which of these can a LocalScript read during Play?

  1. ReplicatedStorage.Shared.Config
  2. The coin pads in Workspace
  3. ServerScriptService.Server.DataService
  4. Its own player's leaderstats
  5. A part in ServerStorage
Answer

ReplicatedStorage.Shared.Config; The coin pads in Workspace; Its own player's leaderstats. ReplicatedStorage, Workspace and the player's own leaderstats folder are replicated. ServerScriptService and ServerStorage never reach a client, so DataService and anything in ServerStorage are invisible to it.

Open this step in lesson mode · Link to this step · This confused me

5Changes travel down, never up

When the server changes a part, every client sees the change. When a client changes a part, only that client sees it. The server keeps its own copy and never hears about the change. Try it in the simulation, then watch the same experiment in Studio.

The arena and the broadcast

The arena and the broadcast: a still of the simulation
Figure 5.1.

Server on the left, two clients on the right. Change values on each side and watch what travels.

Figure 5.2.

The client command bar creates ClientOnly and the server command bar creates ServerMarker. Only one of them crosses.

Transcript
  1. 0:05 The client creates a part named ClientOnly.
  2. 0:12 The server view does not have ClientOnly. A client part does not replicate.
  3. 0:18 The server creates ServerMarker.
  4. 0:21 The client view shows ServerMarker. A server part does replicate.

A LocalScript on Player1's device runs this during Play. What does Player2 see?

local pad = workspace.Yard.CoinPads.Pad1
pad.Color = Color3.new(1, 0, 0)
  1. Pad1 keeps its old colour
  2. Pad1 turns red a moment later
  3. Pad1 turns red only if Player1 owns it
  4. An error appears on Player2's screen
Answer

Pad1 keeps its old colour. The change happened on Player1's client only. It never reaches the server, so it is never broadcast to Player2. Player1 sees red; everyone else, including the server, sees the old colour.

Notice where the referee picture stops fitting. A real referee watches the whole stadium. The Roblox server does not watch each player's screen: it is the field itself, and it cannot see anything a LocalScript creates on a client.

Where does it break?“The referee with the only real scoreboard” is a good picture of the server. Where does it stop being true?

It breaks here. The server is also the field itself, and it cannot see things that exist only on a client, such as a player's GUI or a LocalScript's effects.

The true model. The server runs the authoritative copy of the whole game world. Anything that matters (coins, damage, purchases) is decided there, and clients only see what it replicates to them.

A LocalScript creates a Part named ClientOnly in Workspace and creates a new ShopFrame in PlayerGui. What can a server Script see?

  1. Neither; anything created only on a client never replicates to the server
  2. Both, because the server watches every client
  3. ClientOnly, because it is in Workspace, but not ShopFrame
  4. ShopFrame, because PlayerGui belongs to the player
Answer

Neither; anything created only on a client never replicates to the server. Replication runs only from server to client. The server is blind to parts, GUI changes and effects created locally on a player's device unless the client sends a remote.

Open this step in lesson mode · Link to this step · This confused me

6Where the broadcast picture breaks

A broadcast is one-way and the viewers control nothing. Roblox is not quite that. Each client simulates its own character and sends the movement up, because waiting for the server would make walking feel laggy. That is why a modified client can teleport or run fast, and why the security lesson checks movement on the server.

Where does it break?“The live broadcast” is a good picture of replication. Where does it stop being true?

It breaks here. Only property changes in some containers are sent, and nothing a client changes ever travels back up to the server.

The true model. The server copies changes in replicated containers, such as Workspace and ReplicatedStorage, down to clients. A client's own changes stay on that client unless it asks the server through a remote.

Where does it break?“Your screen and controller at home” is a good picture of the client. Where does it stop being true?

It breaks here. The client also simulates your own character's movement and sends it up, so it is more than a screen.

The true model. Each player's device runs its own copy of the game for display and input. It owns its character's physics by default, which is why movement feels instant and why a cheater can move strangely.

The shop's Speed upgrade sets the player's Humanoid.WalkSpeed to 24 on the server. Why is WalkSpeed a poor place to enforce what a player paid for?

  1. The client controls its own character, so a modified client can set WalkSpeed to anything and move that fast
  2. WalkSpeed does not replicate at all
  3. The server cannot set WalkSpeed
  4. WalkSpeed resets every frame
Answer

The client controls its own character, so a modified client can set WalkSpeed to anything and move that fast. The server decides that speedOwned is true, and that is the real record. But movement is simulated on the client, so the speed a cheater actually moves at is under their control. Server-side movement checks, covered in the security lesson, are the answer.

Open this step in lesson mode · Link to this step · This confused me

7leaderstats is a display copy

Coins live in a table on the server, inside DataService. The number in the player list and on the HUD is a copy: DataService writes it into an IntValue inside a folder called leaderstats, Roblox shows that folder in the player list, and the value replicates to clients so the HUD can read it3.

-- DataService owns each player's coins while they are in this server.
-- Only the server changes a coin count. leaderstats is the display copy:
-- Roblox shows a folder with exactly that name in the player list, and
-- the client may read it but never decides anything from it. Nothing is
-- saved yet, so coins reset when you leave. A later milestone adds
-- DataStore saving to this same module.
Figure 7.1
Roblox Studio
Beacon Yard's HUD during Play: the coin count, the Idle phase and the objective line, with the beacon in the yard behind it.

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

Figure 7.2.

The HUD reads the leaderstat. It never decides the number.

A cheater sets their own leaderstats.Coins.Value to 9999 from a client script and opens the shop. What can they buy?

  1. Only what their server-side profile can afford; the 9999 exists only on their screen
  2. Everything, because the shop reads leaderstats
  3. Everything, until the next save
  4. Nothing; the server kicks them automatically
Answer

Only what their server-side profile can afford; the 9999 exists only on their screen. The client's change never travels up. DataService.trySpend checks profile.coins in the server's own table, so the purchase is decided on the real balance.

Open this step in lesson mode · Link to this step · This confused me

8StreamingEnabled: not everything arrives at once

In a big world, sending every part to every client wastes memory. With Workspace.StreamingEnabled on, the engine sends each client only the parts near its player, and removes far ones4. Studio turns it on by default for new places, and the later Beacon Yard milestones set it explicitly (m14-ship uses a target radius of 512 studs), so the yard relies on it. Even in a small yard, write client code as if a part might not have arrived yet: wait for it with WaitForChild, or react when it appears.

Both sidesBuilding the world near the player (chunks and StreamingEnabled) is stage sets built as you walk.
In the pictureIn Roblox
The stage crew building the next set ahead of youThe server generating chunks near players
Striking a set nobody is onDestroying chunks far from every player
The set drawingsThe seed and generator, which rebuild an identical chunk

See the whole analogy cast

Both sidesRemember: Building the world near the player (chunks and StreamingEnabled) is stage sets built as you walk.

In a streamed place, a LocalScript runs workspace.Yard.CoinPads.Pad6.Color = ... before Pad6 has streamed to the player. What happens?

  1. An error: Pad6 is not a valid member, because it has not streamed in on this client
  2. Pad6 changes colour for everyone
  3. The server streams Pad6 in first, then the line runs
  4. Nothing; streaming only affects the server
Answer

An error: Pad6 is not a valid member, because it has not streamed in on this client. Pad6 exists on the server but not on a client that is far away. Indexing it fails. WaitForChild, or code that reacts when the part streams in, is the safe pattern.

Open this step in lesson mode · Link to this step · This confused me

9Build it: one part on each side, then the HUD

Where should game logic run? Roblox gives you more than one answer, and it is worth knowing them before you choose.

Where gameplay logic runs

OptionWhat it isWhen pros pick itTrade-offs
Server-authoritative rulesThe server decides every outcome; clients send requests and draw results. Beacon Yard's model.Anything with currency, damage, progress or competition. Almost every Roblox game.Every action waits a round trip, so feedback needs care.
Client prediction plus server checkThe client shows the result at once (a swing animation, a coin sparkle) and the server confirms or corrects.Fast actions where waiting feels bad, such as combat.You must handle the server saying no and roll the effect back.
Server authority modelRoblox's newer system where the server simulates characters from client inputs and clients predict and roll back.Competitive games that need movement the client cannot fake.Newer and stricter: it needs Workspace.AuthorityMode set to Server and code written for rollback.
Client-only logicPurely visual or personal things: camera, UI animation, local sounds.Anything nobody else needs to see or trust.Never for rules: a cheater controls their client completely.
  • src/client/Hud.luau
  • src/server/Remotes.luau
  1. At m03-coins-count, press Play. In the client command bar run local p = Instance.new("Part") p.Name = "ClientOnly" p.Anchored = true p.Parent = workspace. Switch to the Server view and look for it in Workspace.

    You should see The server Explorer does not list ClientOnly. The client view does.

  2. In the server command bar run local p = Instance.new("Part") p.Name = "ServerMarker" p.Anchored = true p.Position = Vector3.new(0, 12, 0) p.Parent = workspace. Switch back to the client view.

    You should see The client view shows ServerMarker floating above the yard.

  3. Stop, then run git checkout m04-two-sides.

    You should see Both parts are gone after Stop. git reports you are at m04-two-sides with Hud.luau and Remotes.luau added.

  4. Press Play and collect a coin. The server paid you and then told your client through a remote, which the next lessons open up.

    You should see A +5 toast appears at the bottom of the screen and the coin count in the HUD rises by 5.

Open this step in lesson mode · Link to this step · This confused me

10Challenges

Level 1, Apprentice

Challenge

Prove to yourself that the client folder only draws and asks.

Start from
The game at milestone m06 (download)

Done means

  • You list three files in src/client and say what each one draws or reads
  • You find the comment in init.client.luau that says nothing there grants coins

Hints

  1. Open src/client and read the comment at the top of each file.
  2. init.client.luau starts Hud, ShopGui, CombatClient, SoundClient and CameraClient.

Level 2, Builder

Challenge

Watch replication with two real clients.

Start from
The game at milestone m04 (download)

Done means

  • A two-player Server & Clients test is running
  • Player1 collects a coin; you report what Player1's and Player2's coin counts show
  • You explain why both players see the coin disappear

Hints

  1. Open the test mode menu next to Play on the mezzanine, choose Server & Clients (F7), set 2 Players, and press Start.
  2. The coin is a part the server destroys, so its removal replicates. The coin count is Player1's own leaderstat.

The level 3 challenge wants a part named ServerLesson under Workspace.Yard that every player can see. Where must the code that creates it run?

  1. In MapBuilder, on the server
  2. In Hud.luau, on each client
  3. In Config.luau
  4. In the command bar of each player
Answer

In MapBuilder, on the server. Only parts the server creates replicate to every client. MapBuilder builds the yard on the server, so the marker belongs there.

Level 3, Professional

Challenge

Add a server-created marker that every client can see. The solution is challenges/solutions/client-server.md in the game repo.

Start from
The game at milestone m06 (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("client-server") in the server command bar. Copy the pass code from Output.

Done means

  • MapBuilder.build parents an anchored Part named ServerLesson, size 2, 1, 2, to the yard
  • Nothing on the client creates it
  • The Course Runner prints TEST PASS client_server_marker and a pass code

Hints

  1. Add it after the yard folder exists, near where the pads are made.
  2. The test looks up Workspace.Yard.ServerLesson and checks it is an anchored BasePart.

Open this step in lesson mode · Link to this step · This confused me

11Recap

Recap

  1. Play runs a server and one client per player, with no shared memory. Scripts in ServerScriptService run on the server, LocalScripts in StarterPlayerScripts on each client, ModuleScripts wherever they are required.
  2. Replication copies the server's world down; a client's own changes never travel up. ServerScriptService and ServerStorage are never sent, which keeps server code and data private.
  3. The server owns the rules and the real numbers; leaderstats and the HUD are display copies. Clients do simulate their own character, so movement needs server checks, and a streamed client may not have a part yet.

The server is the referee with the only real scoreboard, until the server is also the field itself, and it cannot see things that exist only on a client, such as a player's GUI or a LocalScript's effects.

Replication is the live broadcast, until only property changes in some containers are sent, and nothing a client changes ever travels back up to the server.

The client is your screen and controller at home, until the client also simulates your own character's movement and sends it up, so it is more than a screen.

Building the world near the player (chunks and StreamingEnabled) is stage sets built as you walk, until there are two crews. Your generator decides what exists on the server; StreamingEnabled separately decides which of it each client has received, so a piece can exist on the server and still be missing on a client.

Next Boot order: what runs first

Open this step in lesson mode · Link to this step · This confused me