What is the difference between remote event and remote function?

i just need to know the difference about remote event and remote function

4 Likes

Remote events are communication from the server to client or the client to server. Just one way. So I can use a remote even to, for example, send a table to the server from the client.

Remote Functions, on the other hand, is communication from the client to the server, and then back to the client (or server to client, and back to server). So I can use a remote function to send a table to the server (from the client), have the server add some values to the table, and then send that table back to the client.

25 Likes

RemoteEvents allow for one-way communication between the client and the server (i.e: Client → Server, Server → Client). With this, you’re basically commanding the server / client to do something without any response.

-- Server

RE.OnServerEvent:Connect(_, msg)
    print(msg)
end)

-- Client

RE:FireServer("Hello world")

RemoteFunctions, on the other hand, allow for two-way communication (i.e: Server → Client → Server (although this is not advised), Client → Server → Client). RemoteFunctions allow you to command the server / client to do something, but also get a response from it

-- Server

function RemoteFunction.OnServerInvoke(_, msg)
    print(msg)
    return "Printed " .. msg .. " in the output in the server"
end

-- Client

local res = RE:InvokeServer("Hello world")
print(res) -- "Printed Hello world in the output"

RemoteFunctions yield the script until they get a response via the return statement

10 Likes

Random question, why is Server > Client > Server not advised? I use it a lot, maybe I shouldn’t

Remote events are one - way communication, remote functions are two way.

A remote event can be used to trigger a server event e.g. teleporting somewhere.
A remote function can be used to ask the server for information only it can see e.g. Items inside server-storage can be returned to the client which they would normally not have access to.

2 Likes

Here are some reasons why:

  • The client may unexpectedly leave the game while the RemoteFunction is being invoked, causing InvokeClient to error causing the game to break
  • If the client throws an error, the server will throw an error as well – game-breaking, also
  • As I mentioned before, RemoteFunctions will yield the server until it gets a response from the client. If the client doesn’t return a value, the server will hang forever – game-breaking, again
8 Likes

Well one of the other reasons that you shouldnt use that unless your not sending really vital information is because exploiters can not only spoof remote events but they can spoof the values of a remote function and send it back to the server, if you use the server > client > server model

1 Like