> For the complete documentation index, see [llms.txt](https://scripter-sm.gitbook.io/elite-zone/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scripter-sm.gitbook.io/elite-zone/getting-started/lifecycle-and-slots.md).

# Lifecycle & slots

What happens when you load, replace or unload a Lua.

## Slots

Elite Zone has **two slots**. You can see them in **settings → lua**:

| Slot    | Shows as                  | Who can sit here                     |
| ------- | ------------------------- | ------------------------------------ |
| Ragebot | `Ragebot Planner: <name>` | `"ragebot planner"` or `"both"` Luas |
| Misc    | `Misc Lua: <name>`        | `"misc"` or `"both"` Luas            |

Each slot holds **one Lua at a time**. A `"both"` Lua sits in both slots.

{% hint style="info" %}
While a Lua is in the Ragebot slot, the ragebot settings in the main tab are hidden behind a **ragebot is controlled by ragebot planner** label, unless the Lua calls `lua:allow_manual(true)`. See api.ragebot.
{% endhint %}

## Lifecycle

```mermaid
stateDiagram-v2
    [*] --> Registered: api.register(name, type)
    Registered --> Active: lua:override()
    Active --> Unloaded: lua:unload()
    Active --> Unloaded: another Lua overrides the slot
    Active --> Unloaded: a hook errors
    Registered --> Unloaded: script errors while loading
    Unloaded --> [*]
```

## Replacing a Lua (overriding)

Say **Lua A** is in the Ragebot slot, and you load **Lua B** (also a ragebot planner).

{% stepper %}
{% step %}

### Lua B calls `override()`

This happens automatically when you load it from the menu.
{% endstep %}

{% step %}

### Lua A is unloaded

Its `on_unload` runs, its connections stop, and its tabs, boxes and custom methods are removed.
{% endstep %}

{% step %}

### Lua B takes the slot

The label changes to `Ragebot Planner: Lua B`, and from the next frame Lua B's hooks run.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
A `"both"` Lua is **one** Lua. If a `"misc"` Lua replaces it, the whole `"both"` Lua is unloaded, so the Ragebot slot becomes empty too.
{% endhint %}

## Saved in configs

Luas you load from **settings → lua → load lua** are saved inside your config. Loading that config later (including your autoload config at startup) loads them again automatically.

* Luas run from your executor are **not** saved, because Elite Zone never sees their code.
* A config without saved Luas leaves your current Luas loaded.
* A Lua that is already loaded with the same code isn't loaded twice.
* To keep your source private, load a one-line `loadstring` loader instead of the Lua itself. See Config makers.

{% hint style="info" %}
Because a saved Lua can load at startup, don't assume a round is already running when your script starts. Check `api.game.status()` or react in a hook.
{% endhint %}

## What gets cleaned up

| If you made it with...     | ...on unload it is                               |
| -------------------------- | ------------------------------------------------ |
| `lua:connect(signal, fn)`  | disconnected                                     |
| `lua:on_changed(idx, fn)`  | stopped                                          |
| `lua:tab(name)`            | removed from the menu                            |
| `lua:box(tab, side, name)` | removed from the tab                             |
| `lua:add_method(...)`      | removed from the dropdown, with its settings box |
| `api.ragebot.desync`       | reset                                            |
| hooks                      | no longer called                                 |
| anything else              | up to you: put it in `lua.on_unload`             |

{% hint style="danger" %}
A plain `signal:Connect(...)` is **not** cleaned up and keeps running after unload. Always use `lua:connect`.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://scripter-sm.gitbook.io/elite-zone/getting-started/lifecycle-and-slots.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
