raknet.OnPacketSend:Once Synchronous

  • RakNet.OnPacketSend:Once

Listen for the next outgoing packet and disconnect automatically before your callback runs. Use it for a one-packet observation without a manual cleanup path.

Syntax
Luau
raknet.OnPacketSend:Once(callback: (RakNetPacket) -> ()) -> RakNetConnection

Parameters

Call this method with a raknet.OnPacketSend receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

Function parameters
ParameterTypeDescription
callback(RakNetPacket) -> ()Function called once with a temporary RakNetPacket.

Argument fields

RakNetPacket fields
Luau
RakNetPacket = {
  Data: buffer, AsArray: {number}, AsBuffer: buffer, AsString: string,
  Size: number, PacketId: number, ID: number, Id: number, PacketID: number, Priority: number,
  Reliability: number, OrderingChannel: number,
  SystemIdentifier: string, Broadcast: boolean, ForceReceiptNumber: number
}

Returns

RakNetConnection

A RakNetConnection, which can be disconnected early if the packet never arrives.

RakNetConnection fields
Luau
RakNetConnection = {Connected: boolean, Disconnect: Function, disconnect: Function}

Usage notes

The RakNet library must be enabled in Environment settings and connected to an active game generation.

Callbacks must not yield. If a callback raises, Kawaii reports a warning and continues dispatching.

The RakNetPacket view is valid only during its callback. Save fields or copy Data inside the callback if you need them later.

Availability

RakNet is disabled by default. RakNet and raknet are removed when the setting is off; retained references can still call is_enabled().

Example

Example
Luau
if raknet.is_enabled() then
    local connection = raknet.OnPacketSend:Once(function(packet)
        print("Next outgoing ID:", packet.ID)
    end)
    task.delay(10, function() connection:Disconnect() end)
end
Kawaii documentation