Packet:SetData
Replaces a packet's raw bytes.
Syntax
Signature
Packet:SetData(Data: string | buffer | {number}) -> ()Aliases
This function has no aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
Data | string | buffer | {number} | Replacement raw payload. |
Returns
| Type | Description |
|---|---|
() | No return values. |
Notes
Accepts a string, buffer, or dense array of byte values from 0 through 255. Payloads must contain 1 through 65,535 bytes. Raises an error on readonly packets or after an editable hook ends.
Example
Luau
-- Send a chat message during the next 15 seconds to see this hook run.
local Hook = network.add_send_hook(function(Packet)
if Packet.type ~= "Chat" then
return
end
local Fields = Packet.decoded
if not Fields then
warn(Packet.decodeError)
return
end
-- Encode a replacement payload, then pass its bytes to SetData.
local Edited = table.clone(Fields)
Edited.text = "[example] " .. Fields.text
local Bytes = network.encode({id = Packet.PacketId, decoded = Edited})
Packet:SetData(Bytes)
end)
task.delay(15, function()
network.remove_send_hook(Hook)
print("Packet editing stopped")
end)