Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Elitriare/ByteNet-Max/llms.txt

Use this file to discover all available pages before exploring further.

definePacket defines a one-way network packet — the ByteNet Max equivalent of a Roblox RemoteEvent. You describe the payload shape with a data type serializer and ByteNet Max handles all buffer writes and reads automatically. The returned object exposes different send methods depending on whether the code runs on the server or the client; calling the wrong method on the wrong side throws an error.

Signature

ByteNetMax.definePacket(props: packetProps<T>) -> PacketDef<T>

Parameters

props
packetProps
required
A configuration table describing the packet.

Return value

A PacketDef object. The methods available depend on the run context.

Server-only methods

sendTo(data, player)
function
Sends data to a single player.
sendToAll(data)
function
Broadcasts data to every player currently in the server. Uses a single buffer write, making it more efficient than iterating with sendTo.
sendToList(data, players)
function
Sends data to each player in the players array.
sendToAllExcept(data, except)
function
Broadcasts data to every player except except.

Client-only methods

send(data)
function
Sends data from the client to the server.

Shared methods

listen(callback) -> () -> ()
function
Registers a callback that fires every time the packet arrives. Returns a disconnect function — call it to remove that specific listener.The callback signature is (data: T, player: Player?) -> (). On the server, player is the sender. On the client, player is always nil.
listenOnce(callback) -> () -> ()
function
Same as listen, but the callback fires only once and then automatically disconnects. Also returns a disconnect function if you need to cancel it before it fires.
disconnectAll()
function
Removes every listener registered on this packet. Useful for cleanup when a system shuts down.
wait() -> T
function
Yields the current thread until the next packet arrives, then returns the data. Implemented with a one-shot listener internally.

Example

-- Shared/Network.luau (ModuleScript)
local ByteNetMax = require(path.to.ByteNetMax)

return ByteNetMax.defineNamespace("Combat", function()
    return {
        packets = {
            DealDamage = ByteNetMax.definePacket({
                value = ByteNetMax.struct({
                    targetId = ByteNetMax.uint16,
                    amount   = ByteNetMax.float32,
                }),
                reliabilityType = "reliable",
            }),
        },
    }
end)
-- Server Script
local Network = require(path.to.Network)

local disconnect = Network.packets.DealDamage.listen(function(data, player)
    print(player.Name, "dealt", data.amount, "damage to target", data.targetId)
end)

-- Later, remove just this listener:
-- disconnect()
-- LocalScript
local Network = require(path.to.Network)

Network.packets.DealDamage.send({
    targetId = 42,
    amount   = 15.5,
})
sendTo, sendToAll, sendToList, and sendToAllExcept are server-only. Calling any of them from a LocalScript throws an error. Likewise, send is client-only and will error if called from a server Script. Always check which context your code runs in if a Script is shared.
ByteNet Max applies a server-side rate limit to incoming client data. By default, each client is allowed up to 8,192 bytes per second. Packets that exceed this budget are silently dropped and a warning is printed to the output. This limit is set via the MAX_BUFFER_SIZE attribute on the ByteNet Max module instance.

Build docs developers (and LLMs) love