Roblox Studio error

OnServerInvoke can only be implemented on the server

What OnServerInvoke can only be implemented on the server means in Roblox Studio, the three things that cause it with the code that triggers each, and the fix for each one.

Updated 12 November 20263 min readErrorLuauWritten by

In short

A RemoteFunction has two halves. The server answers with OnServerInvoke, set in a Script. The client answers with OnClientInvoke, set in a LocalScript. This error means a script set the half that belongs to the other side: a LocalScript set OnServerInvoke, or a server Script set OnClientInvoke. Move the callback into a script on the right side, and keep only the InvokeServer or InvokeClient call where it is.

On this page
  1. What it means
  2. Causes and fixes
  3. Fix it with RoCode
  4. Find the line
  5. Questions
  6. Sources

What the message means

Output (example)
Players.Player1.PlayerScripts.Shop:6: OnServerInvoke can only be implemented on the server

Other forms of the same message:

  • OnClientInvoke can only be implemented on the client

The client asks with InvokeServer and the server answers with OnServerInvoke. The server asks with InvokeClient and the client answers with OnClientInvoke. The ask and the answer are always in different scripts.

The script path in the message tells you which side ran the line: Players.Player1.PlayerScripts or PlayerGui means a LocalScript, ServerScriptService means the server.

Causes and fixes

Three things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.

The LocalScript sets both the call and the answer

Writing the whole RemoteFunction in one LocalScript feels natural, but the client cannot answer for the server.

Breaks LocalScript in StarterPlayer.StarterPlayerScripts named Shop
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getCoins = ReplicatedStorage:WaitForChild("GetCoins") :: RemoteFunction

-- OnServerInvoke can only be implemented on the server
getCoins.OnServerInvoke = function(player)
    return 0
end

print(getCoins:InvokeServer())

Keep the InvokeServer call in the LocalScript and move the callback into a Script in ServerScriptService.

Fixed Script in ServerScriptService named CoinsRemote
-- a Script in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getCoins = ReplicatedStorage:WaitForChild("GetCoins") :: RemoteFunction

getCoins.OnServerInvoke = function(player: Player): number
    local leaderstats = player:FindFirstChild("leaderstats")
    local coins = leaderstats and leaderstats:FindFirstChild("Coins")
    if coins and coins:IsA("IntValue") then
        return coins.Value
    end
    return 0
end

A server Script sets OnClientInvoke

The opposite mix-up gives OnClientInvoke can only be implemented on the client.

Breaks Script in ServerScriptService named Names
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local askName = ReplicatedStorage:WaitForChild("AskName") :: RemoteFunction

-- OnClientInvoke can only be implemented on the client
askName.OnClientInvoke = function()
    return "Player"
end

Set OnClientInvoke in a LocalScript in StarterPlayerScripts. Better still, use a RemoteEvent for messages from the server to a client, because InvokeClient makes the server wait on a client that might never answer.

Fixed LocalScript in StarterPlayer.StarterPlayerScripts named Names
-- a LocalScript in StarterPlayer.StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local askName = ReplicatedStorage:WaitForChild("AskName") :: RemoteFunction

askName.OnClientInvoke = function(): string
    return Players.LocalPlayer.DisplayName
end

A shared ModuleScript sets the callback

A ModuleScript in ReplicatedStorage runs on whichever side requires it. If it sets OnServerInvoke and a LocalScript requires it, the line runs on the client and fails.

Breaks ModuleScript in ReplicatedStorage named Remotes
-- ReplicatedStorage.Remotes, required by both sides
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getCoins = ReplicatedStorage:WaitForChild("GetCoins") :: RemoteFunction

getCoins.OnServerInvoke = function(player)
    return 0
end

return {}

Check the side before setting a callback, or keep server callbacks in a module under ServerScriptService that only the server requires.

Fixed ModuleScript in ReplicatedStorage named Remotes
-- ReplicatedStorage.Remotes, required by both sides
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local getCoins = ReplicatedStorage:WaitForChild("GetCoins") :: RemoteFunction

if RunService:IsServer() then
    getCoins.OnServerInvoke = function(player: Player): number
        return 0
    end
end

return {}

Fix it in your place

Paste the error, RoCode fixes it in your place

Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.

For example: Players.Player1.PlayerScripts.Shop:6: OnServerInvoke can only be implemented on the server

RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.

How to find the line that causes it

  1. Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
  2. Find the first red line. It starts with the script's place in the Explorer and the line number, such as ServerScriptService.Shop:12:.
  3. Click the red line. Studio opens that script with the cursor on the failing line.
  4. Read the lines between Stack Begin and Stack End under it: they list the calls that led there, newest first, so you can see which function called the broken one.
  5. Still not sure which value is wrong? Add print(typeof(x), x) just above the line, or set a breakpoint on it and read the values in the Watch window.

Questions

Where should the RemoteFunction itself be?

In ReplicatedStorage, so both the server and every client can see it. Create it in Studio, or from a server Script before any client calls it.

Can the client set OnServerInvoke to cheat?

No. That is exactly what this error stops: only the server decides what the server answers.

RemoteFunction or RemoteEvent?

A RemoteFunction when the client needs an answer from the server. A RemoteEvent for anything else, and for every message from the server to clients.

Can RoCode fix it?

Yes. Paste the Output line into RoCode. It moves the callback into a script on the right side of your open place and keeps the call where it is.

Sources and further reading

How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 12 November 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the strings in Roblox Studio itself (macOS build installed on 12 November 2026) on 12 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

More Roblox errors

All Roblox Studio errors

Stop hunting errors line by line.

RoCode reads the scripts in your open place, fixes the error where it happens and tells you what it changed. Free every day, no card required.