> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# raknet.add_send_hook

Runs your function on every outgoing packet, just before it leaves the client.

```luau theme={null}
raknet.add_send_hook(hook: function): ()
```

RakNet is how Roblox connects you to the server over the internet. <br />Pretty much the same thing as `RemoteEvent`'s and `RemoteFunction`'s - they do the same job, but in RakNet you work with the raw packets instead of simple remotes.

Your hook receives one `RakNetMessage` for the packet. From inside the hook you can read its payload, replace it with `RakNetMessage:SetData`, or stop the packet with `RakNetMessage:Block`. The hook runs on outgoing packets only. Several hooks can be registered at once and every one of them runs per packet.

## Parameters

| Parameter | Type       | Description          |
| --------- | ---------- | -------------------- |
| `hook`    | `function` | The function to run. |

## Returns

<code title="the function does not return a value.">void</code>

`raknet.add_send_hook` returns nothing. Your hook decides the packet's fate by its return value:

* `return false` - the packet is dropped and never sent.
* `return nil`, or nothing - the packet passes through unchanged.

## Example

Log every outgoing packet's metadata.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  raknet.add_send_hook(function(bitBuffer, channel, reliability)
      return true
  end)
  =======
  -- raknet.add_send_hook(hook: function): ()
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local function packetLogger(packet)
      print("Outgoing packet:")
      print("  Size:", packet.Size)
      print("  Priority:", packet.Priority)
      print("  Reliability:", packet.Reliability)
      print("  Ordering channel:", packet.OrderingChannel)
  end

  raknet.add_send_hook(packetLogger)
  ```
</CodeGroup>

<Tip>
  You need to enable this feature in the UI settings for hooks to run. Using this can lead to account bans.
</Tip>
