Remotes: events, functions, unreliable, buffers

Learn Roblox remotes. RemoteEvent, RemoteFunction and UnreliableRemoteEvent, who creates them, what the server can trust, buffers for bandwidth, rate limiting, and what networking libraries like ByteNet, Zap and Warp add, using Beacon Yard's five remotes.

Concept lesson, about 60 minutes, 11 steps

By the end you can

  • Choose between RemoteEvent, RemoteFunction and UnreliableRemoteEvent for a message, and say what each promises
  • Read a handler and say which argument the engine supplies and which ones the client can forge
  • Pack a small payload into a buffer and compare its size with a plain table
  • Name the engine's remote rate limit and write a per-player limit of your own

Before this: Boot order: what runs first, Types: strict mode, the new type solver, generics

Step 1 of 11

Five names that carry the whole game

Everything one side of Beacon Yard says to the other goes through five objects in ReplicatedStorage.Remotes: RoundState, Feedback, ShopOpen, ShopBuy and Swing. The server creates them, one list in one file. A client that wants the shop to sell it a Speed upgrade does exactly one thing: fire ShopBuy with the word "Speed".

local REMOTE_NAMES: { string } = { "RoundState", "Feedback", "ShopOpen", "ShopBuy", "Swing" }
Roblox Studio
Roblox Studio in the Server view during Play: ReplicatedStorage is expanded to show the Remotes folder with Feedback, RoundState, ShopBuy, ShopOpen and Swing, and Swing is selected.

Select a numbered pin, or a row below, to read what it marks.

The server's view of ReplicatedStorage.Remotes during Play. Five RemoteEvents, all created by Remotes.init.

Work it out

How many RemoteEvents does Beacon Yard's server create at m06?

remotes

Link to this step · This confused me

Step 2 of 11

RemoteEvent: a note to the front desk

A RemoteEventRemoteEventAn object that sends a one-way message between a client and the server.Think of it as a note to the front-desk clerk. carries one message, one way, and the sender does not wait. A client fires it with remote:FireServer(...). The server listens with remote.OnServerEvent:Connect(function(player, ...) end). To go the other way, the server calls FireClient(player, ...) for one player or FireAllClients(...) for everybody, and clients listen with OnClientEvent1.

Both sidesA RemoteEvent is a note to the front-desk clerk.
In the pictureIn Roblox
Writing a noteFireServer from a LocalScript
The clerk reading itOnServerEvent running on the server
The name on the envelopeThe player argument the engine adds

See the whole analogy cast

A RemoteEvent is a note handed to a clerk at the front desk. The clerk reads it later, and you do not stand there waiting for a reply.

Think of it as A note to the front-desk clerk

Look at who is who in the handler's parameters. The engine puts the sender first, and everything after it is whatever the client wrote on the note.

	Remotes.get("ShopBuy").OnServerEvent:Connect(function(player: Player, item: unknown)
		ShopService.purchase(player, item)
	end)

The cell below fakes the desk with a Signal, so you can see the stamping rule. The player is added by the code that delivers the note, never by the sender.

Luau with roblox-lite (not Roblox)
Ctrl Enter runs the cell. Checked against the expected output
Choose one

A modified client fires ShopBuy with the arguments ("Speed", "I am Ben"). In ShopService's handler function(player, item), who is player?

A modified client fires ShopBuy with the arguments ("Speed", "I am Ben"). In ShopService's handler function(player, item), who is player?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 3 of 11

Who fires what

Each of the five remotes has a direction. The server fires three of them to clients and listens to two.

Match the pairs

Match each Beacon Yard remote to what travels on it.

Notice what is missing from the two requests: a price, a damage number, a user id. They are not fields the server wants from a client, so they are not fields at all.

		swing:FireServer(origin, direction)
Choose one

CombatClient fires Swing with an origin and a direction. How much damage does a hit do, and where does that number come from?

CombatClient fires Swing with an origin and a direction. How much damage does a hit do, and where does that number come from?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 4 of 11

RemoteFunction: a phone call on hold

A RemoteFunction is a call that waits for an answer. remoteFunction:InvokeServer(...) pauses the calling script until the server's OnServerInvoke returns a value. It is the right shape for "give me a number and wait for it", such as a client asking for its own inventory.

Both sidesA RemoteFunction is a phone call on hold.
In the pictureIn Roblox
Dialling and waiting on the lineInvokeServer yielding until the server returns
The person answeringThe OnServerInvoke callback
The answer you hearThe value the callback returns

See the whole analogy cast

The danger is on the other side. If the server calls InvokeClient, it yields until the player's device answers. If that client disconnects, InvokeClient throws an error. Worse, if a hung or modified client never returns a value, the server yields forever1. In practice the server rarely invokes a client: clients usually know nothing the server does not.

Beacon Yard has no RemoteFunction at all. The result of a purchase comes back as a later Feedback event, so the shop never sits on hold.

Both sidesRemember: A RemoteFunction is a phone call on hold.

Choose one

ShopService decides whether a purchase worked. Why does it answer with a Feedback event instead of making ShopBuy a RemoteFunction that returns true or false?

ShopService decides whether a purchase worked. Why does it answer with a Feedback event instead of making ShopBuy a RemoteFunction that returns true or false?

Press 1 to 4 to choose, Enter to check.

A real phone call eventually times out or drops cleanly when the other side hangs up. Calling a client from the server does not protect you from a client that keeps the line open forever.

Where does it break?“A phone call on hold” is a good picture of a remotefunction. Where does it stop being true?

It breaks here. If the server calls a player, the player controls the line: a disconnected client throws an error, and a hung or modified client that never returns leaves the server's script yielding forever.

The true model. InvokeServer and InvokeClient yield until a response arrives. A server that invokes a client has no way to force an answer, so servers should avoid depending on clients and should answer with events instead.

Choose one

A server script calls remoteFunction:InvokeClient(player) on a modified client whose OnClientInvoke handler runs task.wait(math.huge) and never returns. What happens to the server thread?

A server script calls remoteFunction:InvokeClient(player) on a modified client whose OnClientInvoke handler runs task.wait(math.huge) and never returns. What happens to the server thread?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 5 of 11

UnreliableRemoteEvent: shouting across a noisy field

An UnreliableRemoteEvent is a RemoteEvent that drops two promises. Messages can be lost, and they can arrive out of order. In return it costs less to send, because the engine does not retry or queue. It suits things that are replaced a moment later: a stream of positions, a sparkle, a footstep sound. It must never carry anything that has to arrive once, such as a purchase2.

Both sidesAn UnreliableRemoteEvent is shouting across a noisy field.
In the pictureIn Roblox
Shouting a positionFireServer or FireClient on an UnreliableRemoteEvent
Some words get lost in the windDropped, unordered messages
Shouting the latest again a moment laterStreaming positions that replace each other

See the whole analogy cast

There is a hard cap: a payload over 1000 bytes is dropped. The cell below sends a stream of positions and loses some, as the network might. Look at what a receiver sees.

Both sidesRemember: An UnreliableRemoteEvent is shouting across a noisy field.

Luau with roblox-lite (not Roblox)
Ctrl Enter runs the cell. Checked against the expected output
Where does it break?“Shouting across a noisy field” is a good picture of an unreliableremoteevent. Where does it stop being true?

It breaks here. Shouting is fine for a position that is replaced a moment later, never for anything that must arrive once; and a payload over 1000 bytes is dropped outright.

The true model. UnreliableRemoteEvent skips resends and ordering to save latency and traffic. It is for continuously changing or short-lived data only; anything that changes game state exactly once belongs on a RemoteEvent.

Retiring the analogy

You no longer need “shouting across a noisy field”. UnreliableRemoteEvent skips resends and ordering to save latency and traffic. It is for continuously changing or short-lived data only; anything that changes game state exactly once belongs on a RemoteEvent.

Choose all that apply

Which of these could safely travel on an UnreliableRemoteEvent in Beacon Yard?

Which of these could safely travel on an UnreliableRemoteEvent in Beacon Yard?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 6 of 11

Buffers: fewer bytes for the same message

Roblox compresses what you send, but a table of named fields still carries names, types and structure. A bufferBufferA fixed block of bytes that you read and write yourself, used to send small, exact payloads.Think of it as a strip of numbered boxes where you decide what goes in each one. is a fixed block of bytes you fill yourself, so you decide exactly how many bytes each value takes3. Writing a number as one byte (writeu8), two (writeu16) or four (writef32) is how libraries cut bandwidth. The cost is that you now write the layout twice, once to pack and once to unpack, and both sides must agree.

Here is a drone update packed into 15 bytes: a one-byte id, three four-byte floats for the position, and a two-byte heading. At m06-drone-wrench, the server updates the drone transform with PivotTo on Heartbeat while the drone is active and unstunned. Sending the 15-byte buffer at 10 Hz gives 150 bytes per second of raw payload per recipient, or 3,000 bytes per second for 20 recipients, before Roblox encodes and transports it. Measure actual traffic with Network Stats in Module 13, The network budget.

Luau
Ctrl Enter runs the cell. Checked against the expected output
Work it out

A packet holds a one-byte id, three four-byte floats and a two-byte heading. How many bytes is the buffer?

bytes

Link to this step · This confused me

Step 7 of 11

Rate limits: the engine's and yours

The engine already throttles each client: about 500 FireServer calls per second, shared by all RemoteEvents of the same type. What happens above that depends on the type. A RemoteEvent's excess calls are processed later, in order, not dropped. An UnreliableRemoteEvent's excess calls are dropped1. That protects the engine, not your game. A player can still fire ShopBuy 400 times a second, and every one of them is a valid request.

Your game's own rule goes on top. Beacon Yard's Swing handler remembers the server time of each player's last swing and refuses another within 0.4 seconds.

	local now = workspace:GetServerTimeNow()
	local previousSwing = lastSwing[player]
	if previousSwing ~= nil and now - previousSwing < SWING_GAP then
		return "rejected"
	end
	lastSwing[player] = now

The cell below is the same rule with a virtual clock. Notice that a refused attempt does not move the clock, so the window opens exactly once per allowed call.

Luau with roblox-lite (not Roblox)
Ctrl Enter runs the cell. Checked against the expected output
Choose one

At m06, Swing has a 0.4 second gap and ShopBuy has none. Which statement is true?

At m06, Swing has a 0.4 second gap and ShopBuy has none. Which statement is true?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 8 of 11

Where the front desk breaks

Both sidesRemember: A RemoteEvent is a note to the front-desk clerk.

A clerk who reads a note with a name on it might believe the name. The engine does something stricter for you.

Where does it break?“A note to the front-desk clerk” is a good picture of a remoteevent. Where does it stop being true?

It breaks here. The engine stamps the sender for you, but every other word on the note can be a lie.

The true model. A RemoteEvent carries a one-way message between a client and the server. The server always learns which player sent it; every other argument is untrusted input that the server must check.

Choose all that apply

ShopService receives ShopBuy(player, item). Which of these can the server trust without checking?

ShopService receives ShopBuy(player, item). Which of these can the server trust without checking?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 9 of 11

Build it: add a Ping, then meet the libraries

You can do everything in this lesson with the engine's own remotes, and Beacon Yard does. Large games often put a library over them. Here is what exists and when professionals reach for it.

Remotes, or a networking library?

OptionWhat it isWhen pros pick itTrade-offs
Plain RemoteEventsThe engine's own objects. Beacon Yard uses these.Most games, especially small and mid-size ones, and everything you are still learning.You write validation by hand, and tables are sent with names and structure, which costs bandwidth.
ZapYou describe events in a small schema file; a compiler generates typed Luau that packs data into buffers and validates what it receives.Games with many events or heavy traffic, and teams that want schema-checked, small packets.A build step and a schema language. Its README calls it an early pre-release, so check the changelog before betting a game on it.
ByteNetA library that serializes your data into buffers using type definitions you write in Luau.Teams that want buffer-sized packets without a separate compiler.Another dependency, and your data must fit its supported types.
WarpA networking library that serializes dynamically, with optional schemas.Teams that want less bandwidth than plain remotes with little setup.Dynamic packing gives up some of what a fixed schema saves.
RedAn older library that packs events through a single remote.You will meet it in existing games.Its repository is archived, so do not start a new project on it.

Build along

m06-drone-wrench

  • src/server/Remotes.luau
  • src/server/init.server.luau
  1. Check out m06-drone-wrench, run rojo serve, press Play, switch to the Server view and expand ReplicatedStorage.Remotes.

    You should see Explorer, in the Server view during Play, lists five RemoteEvents under ReplicatedStorage.Remotes.

  2. Switch to the Client view. In the command bar run game.ReplicatedStorage.Remotes.ShopBuy:FireServer("Nope").

    You should see An Unknown item toast appears at the bottom of the HUD, and your coin count does not change.

  3. With at least 25 coins and no Speed upgrade yet, run game.ReplicatedStorage.Remotes.ShopBuy:FireServer("Speed", 0, "free"). Watch the coin count fall by 25, not by 0.

    You should see A Speed purchase works when you have 25 coins, with no price in the message.

Link to this step · This confused me

Step 10 of 11

Challenges

Level 1, Apprentice

Challenge

Name the five remotes and their directions before looking at the file.

Start from
The game at milestone m06 (download)

Done means

  • You list the five names from memory and mark ShopBuy and Swing as client to server
  • You check your list against REMOTE_NAMES

Meet the criteria above, then record your own result. No test grades this check.

Luau with roblox-lite (not Roblox)
Ctrl Enter runs the cell. Checked by tests

Level 3, Professional

Challenge

Add a Ping remote end to end. The solution is challenges/solutions/remotes.md in the game repo.

Start from
The game at milestone m06 (download)
Grade it
To grade work from an earlier milestone, apply your challenge changes to a checkout based on m14-ship, which includes the Course Runner. In Studio, press Play, then run require(game.ReplicatedStorage.GameTests.RunChallenge)("remotes") in the client command bar. Copy the pass code from Output.

Done means

  • REMOTE_NAMES gains a sixth name, Ping, and the server (not a client) creates it
  • After Remotes.init() in init.server.luau, the server answers Ping with FireClient and the string pong, ignoring the client's argument
  • The Course Runner prints TEST PASS remotes_ping and a pass code

The Course Runner prints this code when the test passes.

Link to this step · This confused me

Step 11 of 11

Recap

Retiring the analogy

You no longer need “a note to the front-desk clerk”. A RemoteEvent carries a one-way message between a client and the server. The server always learns which player sent it; every other argument is untrusted input that the server must check.

Retiring the analogy

You no longer need “a phone call on hold”. InvokeServer and InvokeClient yield until a response arrives. A server that invokes a client has no way to force an answer, so servers should avoid depending on clients and should answer with events instead.

Recap

  1. A RemoteEvent is a one-way message; the engine supplies the sender as the first argument on the server, and everything after it is untrusted. RemoteFunction waits for a reply and can hang a server if it calls a client, so Beacon Yard uses events and answers with Feedback.
  2. UnreliableRemoteEvent may lose or reorder messages and caps a payload at 1000 bytes, so it carries only things that are replaced a moment later. Buffers let you choose each byte, at the cost of writing the layout twice.
  3. The engine allows about 500 client fires a second per remote type; a RemoteEvent delays the excess and an UnreliableRemoteEvent drops it. Your own rules, such as Swing's 0.4 second gap, go on top, and libraries like Zap, ByteNet and Warp are optimizations for heavy traffic.

A RemoteEvent is a note to the front-desk clerk, until the engine stamps the sender for you, but every other word on the note can be a lie.

A RemoteFunction is a phone call on hold, until if the server calls a player, the player controls the line: a disconnected client throws an error, and a hung or modified client that never returns leaves the server's script yielding forever.

An UnreliableRemoteEvent is shouting across a noisy field, until shouting is fine for a position that is replaced a moment later, never for anything that must arrive once; and a payload over 1000 bytes is dropped outright.

Next Security: never trust the client

Link to this step · This confused me