raknet. OnPacketReceive: Wait Asynchronous
RakNet.OnPacketReceive:Wait
Yield until the next incoming packet and receive a copied snapshot. This is useful when a coroutine needs one packet’s data after its event callback has finished.
Luau
raknet.OnPacketReceive:Wait() -> PacketSnapshotParameters
Call this method with a raknet.OnPacketReceive receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
This function takes no arguments.
Returns
PacketSnapshotAn owned PacketSnapshot table with a buffer in Data and packet metadata.
Luau
PacketSnapshot = {
Data: buffer, Priority: number, Reliability: number, OrderingChannel: number,
SystemIdentifier: string, Broadcast: boolean, ForceReceiptNumber: number
}Usage notes
The RakNet library must be enabled in Environment settings and connected to an active game generation.
The wait can remain suspended until matching traffic arrives.
Availability
RakNet is disabled by default. RakNet and raknet are removed when the setting is off; retained references can still call is_enabled().
Example
Luau
if raknet.is_enabled() then
task.spawn(function()
local packet = raknet.OnPacketReceive:Wait()
print("Next incoming payload bytes:", buffer.len(packet.Data))
end)
end