Skip to content

Network

The Network module provides a unified communication layer over a single RemoteEvent and RemoteFunction pair. All networking goes through named string dispatchers — no manual remote management required.

Access via Riptide.Network.

type Callback = (...any) -> any
type Middleware = (...any) -> any
type NetworkAPI = {
Register: (funcName: string, callback: Callback) -> (),
Unregister: (funcName: string, callback: Callback) -> (),
UseMiddleware: (scope: "server" | "client", middleware: Middleware) -> (),
ClearMiddlewares: (scope: ("server" | "client")?) -> (),
-- Server-only
FireClient: ((player: Player, funcName: string, ...any) -> ())?,
FireAllClients: ((funcName: string, ...any) -> ())?,
UnreliableFireClient: ((player: Player, funcName: string, ...any) -> ())?,
UnreliableFireAllClients: ((funcName: string, ...any) -> ())?,
InvokeClient: ((player: Player, funcName: string, ...any) -> any)?,
-- Client-only
FireServer: ((funcName: string, ...any) -> ())?,
UnreliableFireServer: ((funcName: string, ...any) -> ())?,
InvokeServer: ((funcName: string, ...any) -> any)?,
}

Network.Register(funcName: string, callback: Callback) -> ()

Registers a handler for a named network event or request. Multiple handlers can be registered for the same name — all will be called for events, but only the first is used for invokes.

Server example — callback receives player as the first argument:

Riptide.Network.Register("PlayerJumped", function(player, height)
print(player.Name .. " jumped " .. height .. " studs!")
end)

Client example — no player argument:

Riptide.Network.Register("ShowNotification", function(message)
print("Server says:", message)
end)

Network.Unregister(funcName: string, callback: Callback) -> ()

Removes a specific previously registered handler. Pass the exact function reference used in Register.

local function onPing(player, data)
-- handle
end
Riptide.Network.Register("Ping", onPing)
-- Later...
Riptide.Network.Unregister("Ping", onPing)

Network.UseMiddleware(scope: "server" | "client", middleware: Middleware) -> ()

Adds a middleware function to the processing pipeline. Middlewares execute in order of registration and must call next(...) to continue the chain.

Server middleware signature:

Riptide.Network.UseMiddleware("server", function(player, funcName, next, ...)
-- Validate, rate-limit, log, etc.
if not isAuthenticated(player) then
return nil -- block the request
end
return next(...) -- continue to handler
end)

Client middleware signature:

Riptide.Network.UseMiddleware("client", function(funcName, next, ...)
print("[Network] Received:", funcName)
return next(...)
end)

Network.ClearMiddlewares(scope: ("server" | "client")?) -> ()

Clears all registered middlewares. If scope is nil, clears both server and client pipelines.

Riptide.Network.ClearMiddlewares("server") -- server only
Riptide.Network.ClearMiddlewares() -- both

These methods are only available when running on the server. Calling them on the client will error.

Network.FireClient(player: Player, funcName: string, ...any) -> ()

Fires a named event to a specific player.

Riptide.Network.FireClient(player, "DataLoaded", playerData)
Network.FireAllClients(funcName: string, ...any) -> ()

Broadcasts a named event to all connected players.

Riptide.Network.FireAllClients("GlobalNotification", "Double XP activated!")

UnreliableFireClient / UnreliableFireAllClients

Section titled “UnreliableFireClient / UnreliableFireAllClients”
Network.UnreliableFireClient(player: Player, funcName: string, ...any) -> ()
Network.UnreliableFireAllClients(funcName: string, ...any) -> ()

Fires a named event over an UnreliableRemoteEvent. Perfect for high-frequency, non-critical data like particles, hitmarkers, or positional updates where dropped packets shouldn’t stall the network.

Riptide.Network.UnreliableFireAllClients("PlayerRotated", player, CFrame.new())
Network.InvokeClient(player: Player, funcName: string, ...any) -> any

Invokes a handler on a specific client and returns the result. Yields until the client responds.

local clientFps = Riptide.Network.InvokeClient(player, "GetFPS")

These methods are only available on the client. Calling them on the server will error.

Network.FireServer(funcName: string, ...any) -> ()

Fires a named event to the server.

Riptide.Network.FireServer("RequestPurchase", itemId, quantity)
Network.UnreliableFireServer(funcName: string, ...any) -> ()

Fires a named event to the server over an UnreliableRemoteEvent. Use for extremely frequent inputs (like aim direction).

Riptide.Network.UnreliableFireServer("UpdateAimDirection", Vector3.new(0, 1, 0))
Network.InvokeServer(funcName: string, ...any) -> any

Invokes a handler on the server and returns the result. Yields until the server responds.

local inventory = Riptide.Network.InvokeServer("GetInventory")

Under the hood, Riptide creates exactly three remotes inside the package:

Riptide/shared/Remotes/
├── EventDispatcher (RemoteEvent)
├── UnreliableEventDispatcher (UnreliableRemoteEvent)
└── FunctionDispatcher (RemoteFunction)

All named events and invokes are multiplexed through these instances using the funcName string as a discriminator. This eliminates ReplicatedStorage clutter and centralizes all network traffic.