Networking
A module used to simplify client-server communication
Important Note
While the networking module allows you to have typed events, it DOES NOT CHECK THE INPUT! We recommend using a library like Roblox's t to insert runtime checks!
Networking in Roblox can be an annoying process, especially if you have to wire it all together yourself. That's why Quebec has a feature-rich networking library.
Events
The networking library supports two kinds of events: typed and untyped events. Untyped events essentially accept every argument while typed events have strict types for the arguments. Here's an example:
local Networking = require(script.Parent.Quebec.modules.Networking)
-- calling :client() on the event will return the client-sided executor.
-- it was added to improve autocompletions and a way to share events without declaring
-- them multiple times. refer to "Organizing"
local Untyped = Networking.event("Equipitem"):client()
Untyped:fire("Sword", 1, 2, 3) -- this works, as it accepts every argument
Untyped:connect(function (...: any)
print(...) -- prints args
end)
-- note: the parenthesis around the "string, number" are cosmetic in this case
-- but are good practice to group type packs.
local Typed: Networking.Event<(string, number)> = Networking.event("DropItem")
local TypedExecutor = Typed:client()
TypedExecutor:connect(function (item: string, amount: number)
print("dropping", tostring(amount), "x", item)
end)
TypedExecutor:fire("Sword", 1) -- works
TypedExecutor:fire("Sword", false) -- this would show a warning due to type mismatchPlease remember that Quebec does NOT perform runtime type checks.
Functions
The library also supports RemoteFunctions. Just like the events, there are typed and untyped ones. However, this time the parentheses aren't optional. Let me show you:
Organizing
We recommend to create an Events ModuleScript somewhere in ReplicatedStorage where you save all your events so both the server and client can access the same events:
You can then access any executor like this:
Executor Methods
Access a client-side executor by calling :client() on the selected event or function. To access the server-sided executor, call :server() on the selected event or function.
Events
fire(player: Player | { Player }, Args...): ()
Fires the event with the given arguments to the selected player or players
broadcast(Args...): ()
Fires the event with the given arguments to all players
except(player: Player | { Player }, Args...): ()
Fires the event with the given arguments to all players except the given ones
connect(callback: (player: Player, Args...) -> ()): RBXScriptConnection
Connects the callback to the event's OnServerEvent
fire(Args...): ()
Fires the event with the given arguments
connect(callback: (Args...) -> ()): RBXScriptConnection
Connects the callback to the event's OnClientEvent
Functions
invoke(player: Player, ...Args): ...Returns
Invokes the function on the specified players with the given arguments and returns the defined returns
connect(callback: (player: Player, ...Args) -> ...Returns): ()
Connects the callback to the event's OnServerInvoke
invoke(...Args): ...Returns
Invokes the function with the given arguments and returns the specified returns
connect(callback: (...Args) -> ...Returns): ()
Connects the callback to the event's OnClientInvoke
Last updated