Are Remote Functions called from client ran on the server or client?

I just wanna get something cleared up. Ive been dealing with this bug in my game for a while now, and it involves remote functions.

So i was wondering, when you call a remote function from the client and a server script passes a function for that remotefunction, does that function run on the server or the client? Does the server actually run the function and return a result, or does it just give the client the function entirely and let the client sort it out?

For example, lets say i have remoteFunction “functionA” in the workspace, and i have a localscript like this:

local func = game.workspace.functionA

local ans = func:InvokeServer()

and then a server script in the workspace like this:

local func = game.workspace.functionA

local function MoveBrick()
     game.workspace.part.Position = Vector3.new(0,0,0)

     return
end

func.OnServerInvoke = MoveBrick

What i wanna know is does MoveBrick() get executed on the server or the client?

Hello, the code ran on .OnServerInvoke (MoveBrick in this case) would be ran on the server as it is part of a server script. If it was .OnClientInvoke running on a client script, the code would execute on the client.
Hope this helps! :grinning:

1 Like

So what is returned by the invoke is simply a result of the function rather than the function itself?

It would return what the MoveBrick function returns in this case which is nil. If you changed the return line to return “Hello” and did print(ans) on the client script, it would print “Hello” on the client.

1 Like

Cool thanks man, appreciate it

1 Like