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.
Packets are the primary tool for one-way communication in ByteNet Max. They work like Roblox RemoteEvents: you fire a packet from one side, the other side receives it through a listener, and no response is expected. The difference is that every packet payload is defined with an explicit data type, so ByteNet Max can serialize it into a binary buffer before sending and deserialize it back on the other end — reducing bandwidth compared to ordinary remote events.
Defining a packet
Packets are defined inside a namespace using ByteNetMax.definePacket. The required value field specifies the data type of the payload.
local ByteNetMax = require(path.to.ByteNetMax)
return ByteNetMax.defineNamespace("Main", function()
return {
packets = {
Test = ByteNetMax.definePacket({
value = ByteNetMax.struct({
Action = ByteNetMax.string,
Data = ByteNetMax.string,
}),
}),
},
}
end)
Packet API
Packets expose different methods depending on which side of the network boundary you are on.
Server-side methods
| Method | Signature | Description |
|---|
sendTo | sendTo(data, player) | Send the packet to a single player. |
sendToAll | sendToAll(data) | Broadcast the packet to every connected player. |
sendToList | sendToList(data, players) | Send the packet to a specific list of players. |
sendToAllExcept | sendToAllExcept(data, except) | Broadcast to all players except one. |
Client-side method
| Method | Signature | Description |
|---|
send | send(data) | Send the packet from the client to the server. |
Shared methods (available on both sides)
| Method | Signature | Description |
|---|
listen | listen(callback) -> disconnect | Register a callback. Returns a function that disconnects the listener when called. |
listenOnce | listenOnce(callback) -> disconnect | Register a callback that fires exactly once, then disconnects automatically. |
disconnectAll | disconnectAll() | Remove every callback registered through listen or listenOnce. |
wait | wait() -> data | Yield the current thread until the next packet arrives, then return its data. |
sendTo, sendToAll, sendToList, and sendToAllExcept can only be called from the server. send can only be called from the client. Calling either from the wrong context will raise an error.
The disconnect pattern
listen and listenOnce both return a disconnect function. Call that function to remove just that one listener:
local Packets = require(game.ReplicatedStorage.Packets)
local disconnect = Packets.packets.Test.listen(function(data, player)
print(data.Action)
end)
-- Later, when you want to stop listening:
disconnect()
To remove all listeners at once, use disconnectAll:
Packets.packets.Test.disconnectAll()
Complete example
Packets ModuleScript (ReplicatedStorage/Packets):
local ByteNetMax = require(path.to.ByteNetMax)
return ByteNetMax.defineNamespace("Main", function()
return {
packets = {
Test = ByteNetMax.definePacket({
value = ByteNetMax.struct({
Action = ByteNetMax.string,
Data = ByteNetMax.string,
}),
}),
},
}
end)
Server Script — listen for what the client sends:
local Packets = require(game.ReplicatedStorage.Packets)
Packets.packets.Test.listen(function(data, player)
print(player.Name, "sent action:", data.Action)
print("Extra data:", data.Data)
end)
LocalScript — send on key press:
local UserInputService = game:GetService("UserInputService")
local Packets = require(game.ReplicatedStorage.Packets)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or input.KeyCode.Name == "Unknown" then return end
Packets.packets.Test.send({
Action = input.KeyCode.Name,
Data = "Some context about this action",
})
end)
Reliability type
By default, packets are sent reliably (guaranteed delivery and ordering). If you are sending high-frequency, low-importance data such as character positions, you can opt into unreliable delivery to reduce latency at the cost of drop tolerance:
ByteNetMax.definePacket({
value = ByteNetMax.vec3,
reliabilityType = "unreliable", -- "reliable" | "unreliable"
})
For a deeper explanation of the trade-offs, see Reliability.