Scripts Versus LocalScripts In Roblox
Compare Roblox Scripts, LocalScripts, and RunContext, learn where each runs safely, and connect client input to server validation via RemoteEvents.
- Difficulty
- Beginner
- Time Needed
- 15 To 20 Minutes
- Server Script Home
- ServerScriptService (Never Replicated To Clients)
- LocalScript Homes
- StarterPlayerScripts, StarterCharacterScripts, StarterGui, StarterPack
- RunContext Modes
- Legacy, Server, Client (Available On Script Only)
- Cross-Boundary Bridge
- RemoteEvent Inside ReplicatedStorage
Core Differences Between Scripts And LocalScripts
Every Roblox experience is multiplayer by design and splits work across two sides: the Roblox server that owns the official world state, and each connected player's device (the client) that renders graphics and reads keyboard, mouse, touch, or controller input. Choosing between a Script and a LocalScript decides which side runs the code and what services it can reach.
A standard Script (using its default Legacy RunContext) executes on the server. Server code controls shared physics, match timers, DataStore saving, team assignments, and authoritative rewards—and any changes it makes to Workspace replicate automatically to every connected player. A LocalScript runs strictly on one player's device, giving direct access to Players.LocalPlayer, UserInputService, camera controls, and local ScreenGuis, while its edits stay private to that client.
Where Each Script Type Actually Executes
Beginners often wonder why an error-free script prints nothing when playtesting begins. In Roblox Studio, script execution depends heavily on the Explorer container holding the file. Dropping a LocalScript straight into Workspace or ReplicatedStorage leaves it dormant, and putting a server Script inside ServerStorage prevents it from running automatically as well.
- ServerScriptService: Primary home for server Scripts; code stored here stays hidden from player devices and handles core rules and cloud storage.
- ServerStorage: Server-only vault for maps, tools, and server ModuleScripts; standard Scripts placed directly inside will not execute.
- StarterPlayerScripts: Clones LocalScripts into each player once on join; scripts survive character deaths and respawns.
- StarterCharacterScripts: Re-clones fresh LocalScripts every time a player's avatar spawns or resets.
- StarterGui and StarterPack: Run LocalScripts tied to HUD menus or equipped Tools.
- ReplicatedFirst: Sends minimal client loading-screen code to players ahead of the rest of the world.
- ReplicatedStorage: Visible to both sides; ideal for RemoteEvents, shared ModuleScripts, and Scripts configured with RunContext set to Client (LocalScripts do not run here).
How RunContext Changes Modern Roblox Scripting
Every standard Script includes a RunContext property in Properties with three choices: Legacy (default server behavior limited to server containers), Server, and Client. LocalScripts and ModuleScripts do not have a RunContext property. Setting a Script's RunContext to Client allows it to execute on each client directly inside ReplicatedStorage—providing a single stable script location so clicking an Output stack trace jumps straight to ReplicatedStorage rather than a temporary runtime clone inside a player object.
Two RunContext pitfalls deserve extra caution. Never place a Script with RunContext set to Client inside StarterPlayerScripts or StarterCharacterScripts, because Roblox copies starter containers onto each joining player, causing both the template script and its clone to run twice. Likewise, avoid setting RunContext to Server inside ReplicatedStorage, since anything stored in ReplicatedStorage replicates to client devices.
Send Client Input Safely Using A LocalScript
When a player presses a key or clicks a button on screen, client code detects that action locally and forwards a request across the boundary through a RemoteEvent placed in ReplicatedStorage. Put the LocalScript below inside StarterPlayer > StarterPlayerScripts so pressing the E key notifies the server without triggering while the player is typing in chat (handled by the gameProcessed guard).
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local requestBonus = ReplicatedStorage:WaitForChild("RequestBonus")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.E then
requestBonus:FireServer()
end
end)Validate Requests And Reward Players On The Server
The golden rule of multiplayer Roblox engineering is server authority: never let client code dictate coin payouts, item ownership, or cooldown timers. When FireServer() arrives, Roblox automatically supplies the sending Player as the first parameter of OnServerEvent so the server always knows exactly who sent the signal.
Add the paired Script below inside ServerScriptService. It creates the RequestBonus RemoteEvent in ReplicatedStorage, enforces a five-second per-player cooldown strictly on the server, and updates the player's Coins attribute safely.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local requestBonus = Instance.new("RemoteEvent")
requestBonus.Name = "RequestBonus"
requestBonus.Parent = ReplicatedStorage
local lastClaim: { [number]: number } = {}
local COOLDOWN_SECONDS = 5
requestBonus.OnServerEvent:Connect(function(player)
local now = os.clock()
if lastClaim[player.UserId] and (now - lastClaim[player.UserId]) < COOLDOWN_SECONDS then
return
end
lastClaim[player.UserId] = now
local updatedCoins = (player:GetAttribute("Coins") or 0) + 10
player:SetAttribute("Coins", updatedCoins)
print(player.Name .. " claimed a server-verified bonus. Total coins:", updatedCoins)
end)Debug Client Server Timing And Missing Scripts
If an interaction feels instant in Studio yet breaks once published, test under realistic network latency. Real Roblox players commonly experience 100 to 300 milliseconds of ping, whereas solo Studio playtests default to zero delay. Open Studio Settings (Alt + S on Windows or Option + S on Mac), locate Network Simulation, and set inbound and outbound delays between 50 and 150 milliseconds to reveal missing WaitForChild() calls or race conditions early.
During solo testing, toggle the Client and Server button in the mezzanine to inspect what exists on each side—and watch the Output window's blue (client) and green (server) labels to confirm every script is firing in its intended environment.