# Increment

### Endpoint

```
POST /api/v1/data/increment
```

***

### Request Body

| Field          | Required   | Description                                          | Type   |
| -------------- | ---------- | ---------------------------------------------------- | ------ |
| `userId`       | <h3>✓</h3> | The player's Roblox user ID                          | string |
| `key`          | <h3>✓</h3> | The key to increment                                 | string |
| `amount`       | <h3>✗</h3> | How much to add. Defaults to `1`                     | number |
| `defaultValue` | <h3>✗</h3> | Starting value if key doesn't exist. Defaults to `0` | number |

***

### Example Requests

```lua
-- Add 1 (default)
local newValue = Auxvyn.increment(player.UserId, "wins")

-- Add 10
local newCoins = Auxvyn.increment(player.UserId, "coins", 10)

-- Add 1, start at 100 if key doesn't exist
local newLevel = Auxvyn.increment(player.UserId, "level", 1, 1)
```

***

### Example Response

```json
{
  "success": true,
  "value": 510
}
```

#### Returns

The new value after incrementing.

***

### Why Use Increment Instead of Set?

Using `Auxvyn.increment()` is safer than reading a value, adding to it, and writing it back. With `set()` there is a risk of a race condition if two servers are updating the same value at the same time. `increment()` is handled atomically on the server, so the value is always accurate.&#x20;

```lua
-- Don't do this unless necessary:
local coins = Auxvyn.get(player.UserId, "coins") or 0
Auxvyn.set(player.UserId, "coins", coins + 10)

-- Instead do this:
Auxvyn.increment(player.UserId, "coins", 10)
```

***

### Error Responses

| Code  | Reason                                                 |
| ----- | ------------------------------------------------------ |
| `400` | Missing `userId` or `key`, or `amount` is not a number |
| `401` | Missing or invalid API key                             |
| `500` | Failed to increment — try again                        |

***

### 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/api-reference/increment.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.
