# addElementDataSubscriber (Server)

> Subscribes a player to an element data key set with the `"subscribe"` sync mode. The player receives the current value at once and every change after that.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Elements
- **URL**: https://wiki.mymp.gg/en/addElementDataSubscriber

## Syntax

```lua
bool addElementDataSubscriber(element element, string key, player player)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | The element holding the data. |
| `key` | `string` | The data's key. Keys longer than 128 characters are cut, with a warning. |
| `player` | `player` | The player who starts receiving the data. |

## Returns

`true` if the player was subscribed. `false` if the element has no data under that key, the data was not set with `"subscribe"`, or the player is already subscribed.

## Example

```lua
addEventHandler("onPlayerJoin", root, function()
    setElementData(source, "money", 500, "subscribe")
    addElementDataSubscriber(source, "money", source)
end)
```

## See also

- [removeElementDataSubscriber (Server)](https://wiki.mymp.gg/en/removeElementDataSubscriber.md): Unsubscribes a player from an element data key. The player stops receiving that data's changes.
- [hasElementDataSubscriber (Server)](https://wiki.mymp.gg/en/hasElementDataSubscriber.md): Tells whether a player is subscribed to an element data key.
- [setElementData (Server)](https://wiki.mymp.gg/en/setElementData-server.md): Keeps a piece of data on an element and, depending on sync, sends it to the players.
