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

# Cleanup

> What runs when your script unloads.

When your script unloads, the following are cleaned up for you:

* Connections you made with `api.utility.connect`.
* Connections you made with any `api.bind.on*`, `api.legitbot.on*`, `api.ragebot.on*`, `api.client.on*`, `api.players.on*`, or `api.game.on*` signal.
* Controls you added (`AddToggle`, `AddColorpicker`, …) and their saved values.
* Overrides from `OverrideValue`.
* Filters, gates, aim transforms, and force-targets from `api.legitbot`.
* Filters, gates, strafe overrides, and force-targets from `api.ragebot`.
* Your script's tab.

## Manual cleanup

The one thing you should clean up yourself is anything you connected to a **control** (`OnChange`, `OnUpdate`, `OnClick`, `Watch`, …). Those return a function you call to stop listening, so hand it to [api.onUnload](/api/overview#onunload):

```luau theme={null}
local stop = handle:OnUpdate(applyColor)
api.onUnload(stop)
```

If you keep a handle across async work, check [Exists](/ui/classes/element-handle#exists) before using it.
