OnServerEvent can only be used on the serverin Roblox Luau: what it means and how to fix it
What it means
A LocalScript tried to listen to OnServerEvent. That event only fires on the server, when a player's device calls FireServer.
The smallest script that triggers it
-- LocalScript in StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("ShowMessage")
remote.OnServerEvent:Connect(function(text)
print(text)
end)
The fix
-- LocalScript in StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("ShowMessage")
remote.OnClientEvent:Connect(function(text)
print(text)
end)
A LocalScript receives messages from the server through OnClientEvent. OnServerEvent belongs in a server Script.
Common causes
- The listener is in a LocalScript and should use OnClientEvent.
- The code was meant for a server Script and was placed in a LocalScript.
- Client and server halves of a RemoteEvent were written the wrong way round.
Practice this until it sticks
A Deep Dive on RemoteEvents, client and server: 5-minute lessons, each with a quiz. What you miss comes back in the next module. One Deep Dive a day is free. No card.