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.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation