Syntax
local ok, result = pcall(function()
return remote:InvokeServer("catalog")
end)Examples
Serve a bounded query
Create a RemoteFunction named LessonCatalog in ReplicatedStorage. Script in ServerScriptService. The response is server-defined and contains no private state; one request per player per second is accepted.
local Players = game:GetService("Players")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("LessonCatalog")
local last = {}
remote.OnServerInvoke = function(player, action)
if action ~= "catalog" then return nil end
local now = os.clock()
if now - (last[player] or -math.huge) < 1 then return nil end
last[player] = now
return {"Types", "Tables", "Events"}
end
Players.PlayerRemoving:Connect(function(player) last[player] = nil end)Handle failure and a rejected response
LocalScript in StarterPlayerScripts. Run with the server example. pcall catches an error but does not impose a timeout on InvokeServer; keep the server handler short and avoid repeated calls every frame.
local remote = game:GetService("ReplicatedStorage"):WaitForChild("LessonCatalog")
local ok, result = pcall(function()
return remote:InvokeServer("catalog")
end)
if ok and typeof(result) == "table" then
print(table.concat(result, ", "))
else
warn("Catalog unavailable; try again later")
endBest practices
- Assign one OnServerInvoke callback; it is not a signal with Connect.
- Use RemoteEvent for notifications that need no return value.
- Do not call DataStores on every UI query; serve validated session data and use an explicit loading state.
At a glance
- Purpose
- Typed scripting and Roblox development
- File extension
- .luau
- Runs in
- Luau host; Roblox engine examples require Roblox Studio
- Usually used with
- Roblox APIs and Studio
Specifications & further reading
Related Luau documentation
RemoteEvent requests and notifications
RemoteEvent sends a message without waiting for a return value. A client calls FireServer; Roblox supplies the sending Player to OnServerEvent. The server can target one client with FireClient or broadcast with FireAllClients. This example requests a fixed help message, not a reward.Handling errors with pcall and xpcall
Protected calls turn an exception into a success flag and a result. They are useful around operations that can fail outside your control. They do not repair bad state, retry automatically, or mean every error should be ignored.Server authority, validation and rate limits
A valid-looking remote call can still be an impossible game action. Validate both the shape of a request and whether the sender may perform it now. This example lets a nearby living player request a visual switch; it does not trust a client position, target Instance or reward.Luau and Roblox scripting
Start with Luau values and functions, then use Roblox Studio to connect that code to players, Instances and events. Luau is the language; Roblox supplies the game engine APIs. Codectionary supports editing and highlighting, while these Roblox examples run in Studio.
RemoteEvent sends a message without waiting for a return value. A client calls FireServer; Roblox supplies the sending Player to OnServerEvent. The server can target one client with FireClient or broadcast with FireAllClients. This example requests a fixed help message, not a reward.Handling errors with pcall and xpcall
Protected calls turn an exception into a success flag and a result. They are useful around operations that can fail outside your control. They do not repair bad state, retry automatically, or mean every error should be ignored.Server authority, validation and rate limits
A valid-looking remote call can still be an impossible game action. Validate both the shape of a request and whether the sender may perform it now. This example lets a nearby living player request a visual switch; it does not trust a client position, target Instance or reward.Luau and Roblox scripting
Start with Luau values and functions, then use Roblox Studio to connect that code to players, Instances and events. Luau is the language; Roblox supplies the game engine APIs. Codectionary supports editing and highlighting, while these Roblox examples run in Studio.