Packet:SetDecoded

Updates a packet from decoded fields.

Syntax

Signature
Packet:SetDecoded(Fields: table) -> ()

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
FieldstableDecoded fields matching this packet's schema.

Returns

TypeDescription
()No return values.

Notes

Invalid schema fields raise an error. Available for mutable standalone packets and active editable send-hook packets. Incoming observer packets and packets whose hook has ended are readonly.

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

    -- SetDecoded encodes the fields and updates the packet's bytes.
    local Edited = table.clone(Fields)
    Edited.text = "[example] " .. Fields.text
    Packet:SetDecoded(Edited)
    print("Updated outgoing chat:", Edited.text)
end)

task.delay(15, function()
    network.remove_send_hook(Hook)
    print("Packet editing stopped")
end)