How does Networking work in Roblox?

Specifically, I want to know how Remote Events, Remote Functions, the Client - Server communication works in technical terms. What happens when you call :FireServer() on a Remote Event, are packets sent with data containing the arguments you passed? Etc, stuff like that. I really want to dive into the technical terms of these kind of things, because I’m pretty sure it’ll help my understanding of networking in terms of the Client - Server model in Roblox. (If I didn’t really explain well please let me know!)

4 Likes

This may not be the answer you want but don’t worry about implementation details. Just know that through :FireServer, you send stuff to the server.

With good abstractions like the roblox api, you generally don’t need to know the implementation details of something.

Don’t program to implementations, program to interfaces.

2 Likes

Resources:

4 Likes

Hey there, as you know, RemoteEvents/Functions are used to let Scripts communicate with LocalScripts, or either way.

As you maybe know (or not), LocalScripts will only execute for the player it is a descendant of. (As example, you will tell in a LocalScript that a player will paint a brick placed inside the workspace by clicking on something in their ScreenGUI. The player clicking on that will see that the brick would get painted, but the server (and other players) wouldn’t, as it happens inside a LocalScript, hence we use RemoteEvents so other players see the change too.)

Here are some examples :

--Functions

RemoteEvent:FireServer() --Used for client-to-server communication
RemoteEvent:FireAllClients() --Used for server-to-all clients communication
RemoteEvents:FireClient(Instance of player) --Fires the specified client

--Events

RemoteEvent.OnServerEvent:Connect(function() --Fires when that RemoteEvent has been triggered through :FireServer() in a LocalScript

RemoteEvent.OnClientEvent:Connect(function(Instance of player) --Fires through the :FireClient() function, only when the LocalScript containing that code is a descendant of the specified player. All clients fire through :FireAllClients()

Additionally, when firing, you can also carry information through RemoteEvents

--LocalScript
RemoteEvent:FireServer(game.Name)
-- Script
RemoteEvent.OnServerEvent:Connect(function(PlayerWhoFiredThis, game) -- When it gets fired by a LocalScript, the first variable specified will always be the player who fired the event, the next will be the ones you put in into your functions.

Otherwise, the RemoteFunction basically works the same way, with the only difference that it can also send back information to where it came from.

Useful links :

Good day :slight_smile:

1 Like