Whats the Difference between Remote Functions and Events?

I’ve been playing around a lot lately with remote functions and events, and especially how they can be used with datastores. After spending around 3 days looking at code regarding datastores and remote events and functions, I just don’t find a clear difference as to why you would use a remote function when you can just create 2 remote events and trigger them in the separate local and normal scripts.
Client to Server (First Remote Event in the local script)
Server to Client (Second Remote Event in the script)

Yes, I know, people will be saying in the comments that remote functions are for 2 way communications (client to server to client) but wouldn’t it be much simpler just to use 2 remote events?
Thoughts?

2 Likes

RemoteFunctions are typically used to return something, like for example, you need the position of the mouse for something server related, you’d Invoke a RemoteFunction to return the current mouse position to the server, they aren’t typically used to do many events like part color changing and what not

RemoteEvents are the main things that people use are used for Clients to communicate with the Server and vice versa. They allow you to do many things to change stuff that the client can not. A broad example would be a Value in ServerStorage, an area the client can’t go to. So you’d Fire a remoteEvent which has the purpose of changing that value

That’s a brief difference between RemoteFunction and RemoteEvents. RemoteFunctions typically must return something and will cause the script to yield until the RemoteFunction returns what needs to be returned whilst RemoteEvents don’t have to return anything and are generally the thing people use to do things that the Server or Client can’t do without it

5 Likes

According to the Dev API, RemoteEvents can be handled for using 1 way communications such as:

  • A player drinking a potion (Client) and making them invisible (Server)
  • A player’s friend (Server) joining the game and showing the player them (Client)

However, RemoteFunctions are for 2 way communications (And it honestly seems like there’s only 1 major use for it):

  • A projectile cast by a player (Client) will create the properties (Server), and checking if a target was hit it’ll change the player’s stats (Client)

Now I’m sure everyone knows about this, but I’ve wondered the same thing as well here :thinking: I honestly haven’t found the use between using if using multiple RemoteEvents would be different than just using 1 RemoteFunction, but just looking at this now I so happen to find this post:

It seems to depend on how much Remotes you tend to fire performance wise, if you send too much then your game would result in a lot of lag

3 Likes

For my game, you own a store and you sell candy. You can restock shelves, and I have a table on the server that holds every shelf, what that shelf is stocked with and how many of that food are on that shelf. To load in a gui, I use a remote function to tell the server which shelf’s data I am asking for, then the server returns a table with all the information on that shelf. That’s just an example of how they can be used.

3 Likes