Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 37 ยท Multiplayer and Security

The Client-Server Model: Scripts, LocalScripts and Replication

Understand how Roblox runs one server and many clients, what replicates between them, when to use Script, LocalScript and ModuleScript, and why the server must stay in charge.

When you press Play in Studio, a single window opens, and it feels like one program. In a real game it is not. Every Roblox experience runs as one server and many clients. The server is a Roblox computer in a data center that owns the official state of the world. Each client is a player's phone, console or PC that shows the world and sends the player's input.

Understanding this split is the most important idea in multiplayer scripting. Once it is clear, remote events, security and most "why doesn't my script work for everyone?" questions make sense. The Roblox scripts are shown read-only; the runnable examples are JavaScript stand-ins that model a server, two clients and replication.

Two worlds, one experience

The server holds the real world. Each client holds its own copy of it, kept in sync by Roblox. Information flows like this:

  • Server to client: changes the server makes to shared objects (like the position of a part in Workspace) are replicated to every client automatically.
  • Client to server: most changes a client makes stay on that client. They are not replicated, with a few exceptions, such as the player's own character movement, which the client controls.

This design is called server authority. The server decides what is true; clients ask for things and display results. It is why a cheater who edits their own client cannot simply give themselves a million coins: the edit never reaches the server.

One server, many clients

Server Owns the true game state.
Clients Show the world and send input.
Replication Server changes flow to clients.
Client edits Stay local. The server never sees them.

Never trust the client for anything that matters.

1 / 2

Which script runs where?

Roblox has three script types, and where you place them decides where they run.

Type Runs on Typical home
Script Server (or client, if its RunContext is set to Client) ServerScriptService, Workspace
LocalScript Client StarterPlayerScripts, StarterGui, StarterCharacterScripts
ModuleScript Whichever side requires it ReplicatedStorage, ServerStorage

Modern Roblox also lets a Script run on the client when you set RunContext to Client. Either way the rule is the same: code runs on the side that has the matching context, and it only sees the objects that side can see.

You can ask where you are:

LUA
local RunService = game:GetService("RunService")

if RunService:IsServer() then
	print("This code is running on the server")
elseif RunService:IsClient() then
	print("This code is running on a client")
end

What each side can see

Containers have different visibility, which is a major tool for security:

  • ServerScriptService and ServerStorage: server only. Clients cannot see them, so put secret logic and templates here.
  • ReplicatedStorage: visible to both. Good for shared modules and remotes.
  • Workspace: replicated to everyone.
  • StarterGui, StarterPlayer contents: copied to clients.
  • ReplicatedFirst: sent to clients first, used for loading screens.

If a LocalScript tries game.ServerStorage.Sword it gets nothing: the client simply does not have that object.

What replicates and what does not

A server script that sets part.Color = Color3.new(1, 0, 0) changes that part for everyone. A LocalScript that does the same changes the part only on that player's screen. Other players, and the server, still see the old color.

That is useful for private effects: a local hint highlight, a hit marker only the shooter sees, or a smooth camera shake. It is dangerous when a beginner expects a local change to be shared. If a button's effect should affect other players, the client must ask the server to do it. That request is the job of remote events.

A server and clients you can run

This JavaScript model has a server world, two clients, and a replicate step. Client changes are local; server changes are copied to all clients.

JS Server authority and replication (JavaScript stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Ana's million coins existed only in her local copy. As soon as the server replicates, the truth overwrites her fake value with 25.

Designing with the model

A useful rule of thumb: the client does the feeling, the server does the truth.

  • The client handles input, camera, animations, sounds, particle effects and interface. These need to feel instant, and they do not need to be trusted.
  • The server handles damage, currency, inventory, saving, round rules, anything that other players depend on or that costs money.
  • When the client wants something real to happen, it asks; the server checks and decides; the result is replicated back.

This is also why the interface in GUI basics lives in LocalScripts, while saving in DataStores lives in server Scripts.

JS Who should decide? A quick sorting exercise

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Common mistakes

  • Expecting a LocalScript change to be visible to others. It is local only. Ask the server.
  • Putting server logic in a LocalScript. It can be read and altered by exploiters.
  • Putting secrets in ReplicatedStorage. Anything the client can see can be copied. Keep keys, loot tables and rules in server-only containers.
  • Running a LocalScript from Workspace or ServerScriptService. It will not run there (unless you set a client RunContext on a Script); local code belongs in client containers.
  • Not waiting for objects. A client may run before replication finishes, so use WaitForChild for things the server creates.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. If a LocalScript changes a part's color in Workspace, who sees the change?

    Client changes are not replicated, so only that player's own screen shows the new color.
  2. 2. Where should secret server-only logic be stored?

    Clients cannot see the server-only containers, so the code cannot be read or changed by exploiters.
  3. 3. What does "server authority" mean?

    The server holds the official state. Clients cannot change it directly, which prevents most cheating.
  4. 4. Which job belongs on the server?

    Money, inventory and rules affect everyone and must be trusted, so the server performs them.

Summary

  • Every experience is one server plus many clients; the server owns the truth.
  • Server changes replicate to clients; client changes stay local.
  • Script runs on the server, LocalScript on the client, ModuleScript on whichever side requires it.
  • Put secrets in ServerScriptService or ServerStorage; shared code in ReplicatedStorage.
  • The client handles feel and input; the server handles decisions, money and saving.

Next: Remote Events: Talking Between Client and Server