# StateBag

## 🧠 Arena PvP — Statebag (`.inArena`)

This page explains the **statebag variable used by Arena PvP** and how it behaves.

Statebags are used internally by the script and also by many frameworks (like QBCore & ESX) to sync important player state data between the server and all clients.

In Arena PvP, the relevant statebag is:

```
Player.state.inArena
```

***

### 🧩 What is `.inArena`?

The `.inArena` statebag is a **boolean flag** that tells the server and clients whether a player is currently inside an Arena session.

| Value   | Meaning                             |
| ------- | ----------------------------------- |
| `true`  | Player is currently inside an Arena |
| `false` | Player is NOT in an Arena           |

`Example: Player.state.inArena = true`&#x20;

This means the player has joined an Arena match or is currently playing.

***

### 📡 When is `.inArena` set?

The script automatically updates this statebag in the following cases:

#### ✔️ Player joins an Arena

When a player enters an Arena match, the script sets: `Player.state.inArena = true`

This tells the clients and framework that the player is now active in an Arena match.

***

#### ✔️ Player leaves an Arena

When a player exits either by finishing the match or using the exit command:

`Player.state.inArena = false`

This means the player has left the Arena.

***

### 🤝 Why is this important?

#### 1️⃣ Framework Compatibility

Most frameworks (like QBCore, ESX, etc.) use statebags to know whether a player should:

* Keep weapons on disconnect
* Disable certain controls
* Restrict certain actions while inside minigames

The `.inArena` flag helps scripts and resources differentiate:

`if Player.state.inArena then`\
`-- Player is in Arena`\
`else`\
`-- Player is not in Arena`\
`end`

***

### 📌 How other scripts can use `.inArena`

If another script needs to behave differently for players who are inside Arena PvP, you can use:

```lua
local inArena = Player.state.inArena

if inArena then
    -- Prevent inventory access
    -- Disable certain actions
    -- Restrict teleporting
end
```

### 🛠 Use Cases

Here are some common use cases:

#### 🎮 Disable unwanted controls

Some scripts disable keybinds when in Arena:

```
if Player.state.inArena then
    DisableControlAction(0, 289) -- Example
end
```

#### 🚪 Prevent teleporting while in Arena

If a player tries to teleport or leave the game world while in an Arena match, you can check:

```
if Player.state.inArena then
    -- block teleport
end
```
