Skip to Content

Scripts

Script execution contexts, parenting, startup order, scheduling rules and runtime limits.

Server and client scripts

A script's execution context is set by its Runs on property.

Server scriptClient script
Runs onThe server, onceEach connected client
World accessRead and writeRead only. Writes go through Remote
VisibilityEvery player, part and modelReplicated objects only
ServicesPlayers, World, Teams, Tools, Remote, State, DataStore, StoragePlayers, World, Teams, Remote, State, UI, Effects, Input, Tools, Build

Authoritative game state (scoring, damage, doors, round flow) belongs on the server. Local presentation (menus, input handling, screen effects) belongs on the client.

Clients are untrusted

Client scripts can be modified by the player. Any decision that affects game state must be made and validated on the server.

Parenting

script.Parent depends on where the script is placed in the Explorer.

Locationscript.Parent
Inside a partThe part (server scripts)
Inside a modelThe model (server scripts)
Inside a toolThe tool (server and client)
In the Scripts foldernil

Client scripts inside parts and models receive nil. Use game:GetService("World"):FindFirstChild(name) to resolve parts on the client.

local door = script.Parent

door.Touched:Connect(function(player)
	door.Transparency = 0.5
	door.CanCollide = false
end)

Scripts can contain value objects, accessed by name, for example script.Damage.Value.

Startup order

Server scripts start when the server loads the world. game.Started fires after every server script has started. Client scripts start on each client after the world has loaded.

Scripts inside Storage do not run until their container is cloned into the world, and stop when the clone is destroyed.

Scheduling

Scripts are cooperatively scheduled. A task that runs for more than one second without yielding is terminated, and a script is stopped after three such terminations. Long-running loops must call task.wait().

while true do
	task.wait(1)
	print("Still going")
end

See Globals for task.wait, task.delay and task.spawn.

Errors and Output

print and warn write to Studio's Output during tests, and to the in-game console for the game's owner. Errors report the script name, line number and message. An error terminates the task it occurred in; other tasks in the script continue.

Limits

LimitAmount
Scripts in one world64
Memory for one script16 MB
Running tasks in one script512
Event connections in one script2048
Time without yielding1 second

On this page