I keep getting the error “InvokeServer can only be called from the client”
The function script
local rep = game.ReplicatedStorage
script.Parent.MouseClick:Connect(function()
game.ReplicatedStorage.FirstQuest:InvokeServer()
end)
The ServerScriptService script
local rep = game.ReplicatedStorage
Player = game.Players.LocalPlayer
game.ReplicatedStorage.FirstQuest.OnServerInvoke = (function()
print("ClickDetector clicked")
print("FirstQuest is now starting for",Player.Name)
end)
Please help
Oh this is confusing the heck out of me
You flipped the 2 functions/events in different places, switch the InvokeServer
on the client script, and put OnServerInvoke
on the server please
Also change your ServerScriptService
script to a LocalScript, you can’t get the player like that
--Server Side
local rep = game.ReplicatedStorage
rep.FirstQuest.OnServerInvoke = function(Player)
print("ClickDetector clicked")
print("FirstQuest is now starting for",Player.Name)
end)
--Client Side
local rep = game.ReplicatedStorage
local ClickDetector = --Parent the ClickDetector object here
ClickDetector.MouseClick:Connect(function()
game.ReplicatedStorage.FirstQuest:InvokeServer()
end)
2 Likes
You didn’t change it to a LocalScript
, change it & put it in StarterPlayerScripts
1 Like
Thanks lol I’ve always hated working with RemoteEvents and RemoteFunctions
1 Like
Ah it’s fine I always just use this analogy to easily remember those Objects:
“Think of a delivery truck that’s delivering goods from Location A to Location B”, it’s pretty much just waiting for event to be fired when you function it, then you can pass your stuff, just make sure to place it in the opposite side (If it’s client, do it from the server, if it’s server, do it from the client & etc)
1 Like