# 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()
```

***
