Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.

← Back to journey

Give the server ownership of shared state

v2 · Activity 1 of 0 · client-server · replication · authority · 28 min Requires Roblox Studio

Chapter outline
Loading draft…
Mini-mission

The server creates a practice Coins attribute on each Player. Replication lets clients display that value. The browser cannot demonstrate this engine behavior.

A LocalScript is controlled by the client. A local coin change or a button claiming a reward is not trusted evidence that the server awarded anything.

Your task

Initialize Coins to 10 on the server. Display it on the client. Temporarily change it locally and compare the server view to understand the boundary.

Interface: Complete the documented Studio hierarchy and self-check the behavior outside the browser.

InputExpected
Syntax in this activity

New syntax: client-server, replication, authority

Earlier ideas used here
  • script-locations
  • execution-context
Self-check rubric
  • The server owns the initialized Coins value.
  • Two clients observe their own state.
  • Explain the local modification result using the separate server view.

Your explanation is a self-check. Exact wording is not automatically graded.

Self-checked Studio exercise. A saved checklist records your own review; no uploaded place file or screenshot is executed here.

Build this hierarchy

ServerScriptService
  OwnedState (Script, RunContext=Server)
StarterPlayer/StarterPlayerScripts
  ObserveState (LocalScript)
  1. Use the script files and a Baseplate.
  2. During a test client session, use its command bar to set LocalPlayer Coins to 999. Read the Player attribute in the server view separately.
ServerScriptService/OwnedState.server.luau

Main guided reference implementation; use the hierarchy’s stated Script or ModuleScript type.

local Players = game:GetService("Players")
local function initialize(player)
    player:SetAttribute("Coins", 10)
end
Players.PlayerAdded:Connect(initialize)
for _, player in ipairs(Players:GetPlayers()) do initialize(player) end
ServerScriptService/OwnedState.server.luau

Server creates the practice state.

local Players = game:GetService("Players")
local function initialize(player) player:SetAttribute("Coins", 10) end
Players.PlayerAdded:Connect(initialize)
for _, player in ipairs(Players:GetPlayers()) do initialize(player) end
StarterPlayer/StarterPlayerScripts/ObserveState.client.luau

Client prints updates and the current value; initial replication can still be pending.

local player = game:GetService("Players").LocalPlayer
local function display() print("Displayed coins", player:GetAttribute("Coins")) end
player:GetAttributeChangedSignal("Coins"):Connect(display)
display()

Expected output

  • The server Player has Coins=10.
  • Clients display the replicated value; a temporary nil before replication is possible.
  • A deliberate client-only change does not become a server-authorized award.

Studio assessment checklist

Multiplayer tests

  1. Inspect Player attributes in one server and two client views.
Troubleshooting and production considerations

An initial nil means the attribute has not arrived yet; the change signal displays the subsequent value.

Do not use the client console as evidence of server ownership.

This is a bounded learning lab. It has not been executed in an approved Roblox Studio environment by this website.

A checked checklist records your own review, not automated project competence or a community verification.

Your goal

Initialize Coins to 10 on the server. Display it on the client. Temporarily change it locally and compare the server view to understand the boundary.

Reset starter

Replace this code with the starter? Download your draft to keep a copy.

Code

Studio source file
Luau keyword highlighting · Ctrl/⌘ + Enter: Run · Esc: leave editor

Edit and run these files in Roblox Studio. This browser has no Roblox services, physics, or replication.

Your output will appear here.

Ready