Difference between Invoke Server and Fire Server?

I am wondering what the difference is between invoke server and fire server? I’ve read the roblox docs and as far as I know it’s basically the same? Also, when should I use Invoke Server instead of FireServer

Thanks

7 Likes

Invoke server is only used for remote functions. Fire server is only used for remote events.

But it’s basically the same right, both from client to server

The difference between the two is the response.

RemoteEvent will only send a request, but it will not expect a response from the receiver.

RemoteFunction will send a request and is expected a response from the receiver.

3 Likes

InvokeServer yields until a value is returned by the server

-- client
local result = Event:FireServer(13) -- doesn't yield
print(result) -- nil, RemoteEvents don't wait for a value to be returned

-- server
Event.OnServerEvent:Connect(function(plr, num)
  wait(num)
  return -- Wouldn't return anything to the client
end)

-- client
local result = Function:InvokeServer(9) -- would yield (pause the script) for 9 seconds
print(result) -- 'Done!'

-- server
Function.OnServerInvoke = function(player, num)
  wait(num)
  return 'Done!'
end

I would suggest looking at this

10 Likes

The short of it should be:

  • Use InvokeServer on a RemoteFunction if you need to wait for a result to come back (or it’s imperative that the code yields until the server deals with whatever it’s doing)
  • Use FireServer on a RemoteEvent for anything else
4 Likes