> For the complete documentation index, see [llms.txt](https://docs.boii.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.boii.dev/fivem-free-resources/bdsc/api/player-object.md).

# Player Object

The player object provides a clean public interface for interacting with a specific player in BDSC.

Each player is represented by a dynamically extendable object that supports:

* Accessing and modifying custom data
* Syncing values to the client
* Adding and running namespaced methods
* Lifecycle functions like `save()` and `destroy()`

All logic attached to a player should go through this API — not directly via internal tables.\
Use `bdsc.get_player(source)` to retrieve the player object, then call methods like `player:get_data()` or `player:run_method(...)` to interact with it.

***

## has\_data

Check if the player has a data namespace assigned.

#### Parameters

* namespace: `string`

#### Returns

* `boolean` – True if it exists.

```lua
player:has_data("stats")
```

***

## get\_data

Retrieve data from a specific namespace.

#### Parameters

* namespace: `string`

#### Returns

* `table|any`&#x20;

```lua
local stats = player:get_data("stats")
```

***

## add\_data

Add a new data namespace to the player.

#### Parameters

* namespace: `string`&#x20;
* value: `any`&#x20;
* replicated?: `boolean`&#x20;

#### Returns

* `boolean|nil`

```lua
player:add_data("stats", { health = 100 }, true)
```

***

## remove\_data

Delete an existing data namespace.

#### Parameters

* namespace: `string`&#x20;

```lua
player:remove_data("stats")
```

***

## set\_data

Update values inside an existing namespace (must be a table).

#### Parameters

* namespace: `string`
* updates: `table`
* sync?: `boolean`

#### Returns

* `boolean`

```lua
player:set_data("stats", { health = 80 }, true)
```

***

## sync\_data

Force replication of a namespace to the client.

#### Parameters

* namespace?: `string`

```lua
player:sync_data("stats")
```

***

## update\_user\_data

Update a value inside the persistent user block and propagate it to storage.

#### Parameters

* key: `string`
* value: `any`

```lua
player:update_user_data("rank", "admin")
```

***

## add\_method

Add a new dynamic method to the player.

#### Parameters

* namespace: `string`
* name: `string`&#x20;
* fn: `function(player, ...)`&#x20;

```lua
player:add_method("combat", "take_damage", function(self, amount)
    local stats = self:get_data("stats")
    stats.health = stats.health - amount
end)
```

***

## remove\_method

Remove a method from the player.

#### Parameters

* namespace: `string`
* name: `string`

```lua
player:remove_method("combat", "take_damage")
```

***

## has\_method

Check if a player has a method defined.

#### Parameters

* namespace: `string`
* name: `string`

#### Returns

* `boolean`

```lua
if player:has_method("combat", "take_damage") then
    ...
end
```

***

## run\_method

Execute a method that was added to the player.

#### Parameters

* namespace: `string`
* name: `string`
* ...: any

#### Returns

* `any`&#x20;

```lua
player:run_method("combat", "take_damage", 25)
```

***

## save

Call `on_save()` method for all namespaces if defined.

```lua
player:save()
```

***

## destroy

Triggers `on_destroy()` for all namespaces if defined, saves the player, and unregisters it.

```lua
player:destroy()
```

***


---

# 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 dynamically by asking a question.

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

```
GET https://docs.boii.dev/fivem-free-resources/bdsc/api/player-object.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
