Open Asterune
Server and client

Server and client

Configure script execution, replication, and remote communication.

The server maintains authoritative game state. Each client renders its view and runs client scripts. Replication sends supported server state to clients. Client changes normally remain local.

Execution context

Script classExecutionContainers
ScriptServerServerScriptService, workspace
LocalScriptClientSupported player script containers, StarterGui, player backpack
ModuleScriptCalling runtime, on first requireA container accessible to the caller

A Script in StarterGui and a LocalScript in workspace do not execute. RunService:IsServer() and IsClient() identify the current runtime.

Replication and storage

Replication depends on the instance container and member metadata. Consult the reference page for replication restrictions.

Required children may not have arrived when a client script starts. Use WaitForChild where a lookup depends on replication.

Send a remote event

Create a RemoteEvent on the server in ReplicatedStorage. The following pair uses a remote named Ready.

Server:

Luau
local remote = Instance.new("RemoteEvent")
remote.Name = "Ready"
remote.Parent = game:GetService("ReplicatedStorage")
remote.OnServerEvent:Connect(function(player)
  print(player.UserId)
end)

Client:

Luau
local storage = game:GetService("ReplicatedStorage")
local remote = storage:WaitForChild("Ready")
remote:FireServer()

OnServerEvent receives the engine-supplied sending player before message arguments. FireClient(player, ...) sends to one client; FireAllClients(...) sends to all clients. OnClientEvent receives message arguments without a leading player argument.

Request a return value

RemoteFunction yields the caller until the remote callback returns. Assign OnServerInvoke or OnClientInvoke; these are callback properties. Reassignment replaces the callback.

InvokeServer propagates callback errors to the calling client. Use pcall for expected failures. InvokeClient can leave a server thread waiting for an unresponsive client until the 600-second timeout. Use RemoteEvent when a synchronous return value is unnecessary.

Validate client requests

Validate argument types, ranges, referenced instances, permissions, and current server state before applying changes. Determine prices, rewards, and eligibility from server-owned state. Client-side validation cannot enforce server rules.

Rate-limit requests that perform substantial computation or storage operations.