RakNetPacket: SetData Synchronous
Replace the bytes in the current packet view before it continues through observers and transport. Use it when you know the exact encoded packet format and need a deliberate rewrite.
Luau
RakNetPacket:SetData(data: PacketData) -> ()Parameters
Call this method with a RakNetPacket receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
| Parameter | Type | Description |
|---|---|---|
data | PacketData | Replacement string, buffer, or dense 1-based array of bytes from 0 to 255. |
Argument fields
Luau
PacketData = string | buffer | {number}Returns
()No value.
Usage notes
The RakNetPacket view is valid only during its callback. Save fields or copy Data inside the callback if you need them later.
A packet that continues to the transport can contain at most 268,435,455 bytes. Empty data suppresses delivery. Replacing a real packet requires a protocol-correct payload.
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
local connection = raknet.OnPacketSend:Connect(function(packet)
-- Copy the current bytes without changing their meaning.
packet:SetData(packet.AsBuffer)
end)
task.delay(5, function() connection:Disconnect() end)
end