# Player Data

### How It Works

When your game calls `Auxvyn.set()`, the value is sent to Auxvyn's servers and stored in the cloud against that player's Roblox user ID. The next time that player joins, even on a different server, your game can call `Auxvyn.get()` to retrieve it.

Every piece of data is stored as a **key-value pair**:

* **Key** — a string that identifies what the data is, like `"coins"` or `"level"`
* **Value** — anything you want to store: a number, string, boolean, or table

***

### Data Structure

Each player can have as many keys as your plan allows. Every record looks like this:

| Field            | Description                       |
| ---------------- | --------------------------------- |
| `roblox_user_id` | The player's Roblox user ID       |
| `key`            | The name of the data field        |
| `value`          | The stored value                  |
| `updated_at`     | When this record was last changed |

***

### Reading and Writing Data

#### Set a value

```lua
Auxvyn.set(player.UserId, "coins", 500)
```

#### Get a single value

```lua
local coins = Auxvyn.get(player.UserId, "coins")
```

#### Get all values for a player

```lua
local data = Auxvyn.getAll(player.UserId)
-- returns { coins = 500, level = 3, ... }
```

#### Increment a numeric value

```lua
-- Adds 10 to coins, returns the new value
local newCoins = Auxvyn.increment(player.UserId, "coins", 10)
```

#### Delete a single key

```lua
Auxvyn.delete(player.UserId, "coins")
```

#### Delete all data for a player

```lua
Auxvyn.delete(player.UserId)
```

***

### Best Practices

#### Save on leave, load on join

The most common pattern is to load a player's data when they join and save it when they leave:

```lua
game.Players.PlayerAdded:Connect(function(player)
    local coins = Auxvyn.get(player.UserId, "coins") or 0
    -- apply to leaderstats, etc.
end)

game.Players.PlayerRemoving:Connect(function(player)
    Auxvyn.set(player.UserId, "coins", currentCoins)
end)
```

#### Always handle the server shutdown case

Roblox can shut down a server at any time. Use `game:BindToClose` to make sure data is saved even during unexpected shutdowns:

```lua
game:BindToClose(function()
    for _, player in ipairs(game.Players:GetPlayers()) do
        Auxvyn.set(player.UserId, "coins", getCurrentCoins(player))
    end
end)
```

#### Use default values

`Auxvyn.get()` returns `nil` if a key doesn't exist yet — for example a brand new player who has never played before. Always handle this:

```lua
local coins = Auxvyn.get(player.UserId, "coins") or 500
```

#### Don't save every second

Calling `Auxvyn.set()` too frequently puts unnecessary load on the API and counts against your request limits. Save on meaningful events, when a player earns coins, completes a level, or leaves the game, rather than on a tight loop.

***

### Viewing Data in the Dashboard

All player data is visible in the **Database** tab of your workspace. You can:

* Browse all players who have data stored
* Click any player to see every key and value they have
* Edit a value directly from the browser
* Delete individual keys or all data for a player
* Refresh to see the latest records

<figure><img src="/files/gyAC3Fz7E8m7cnSFncAT" alt=""><figcaption></figcaption></figure>

***

### Editing Data from the Dashboard

You can edit any player's data directly from the Database tab without touching your game code. This is useful for:

* Fixing corrupted data
* Granting items or currency manually
* Testing how your game responds to specific values
* Moderating players

<figure><img src="/files/zeIgfw5o0FUhPxGacTSH" alt=""><figcaption></figcaption></figure>

If you have **Live Sync** configured, edits made in the dashboard are pushed to the player instantly if they are currently in your game. See Live Sync for setup instructions.

***

### Data Limits

| Plan | Storage | Records                |
| ---- | ------- | ---------------------- |
| Free | 10 MB   | Limited to storage cap |
| Pro  | 5 GB    | Limited to storage cap |

***

### Data Safety

* Data is stored in the cloud and persists indefinitely until you delete it
* Auxvyn does not delete your data automatically
* Deleting a workspace permanently deletes all player data inside it with no recovery
* Revoking an API key does not delete any data

***

### What's Next


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auxvyn.gitbook.io/auxvyn-docs/core-concepts/player-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
