# setElementData (Client)

> Keeps a piece of data on an element, on this client only.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Elements
- **URL**: https://wiki.mymp.gg/en/setElementData-client
- **Counterpart**: Also exists on the server, with its own implementation: [setElementData (Server)](https://wiki.mymp.gg/en/setElementData-server.md)

## Syntax

```lua
bool setElementData(element element, string key, any value [, bool|string sync = true])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | The element. |
| `key` | `string` | The data's name. Keys over 128 characters are cut, with a warning. |
| `value` | `any` | The value to keep. |
| `sync` | `bool\|string` | Accepted as on the server (`true`, `false`, `"broadcast"`, `"local"` or `"subscribe"`), but ignored. Any other value raises an error. *(default: `true`)* |

## Returns

`true` if it was kept, `false` if the element already held that same value.

Fires `onClientElementDataChange`. Cancelling the event does not undo the change.

## Example

```lua
setElementData(localPlayer, "hud.visible", false)

if getElementData(localPlayer, "hud.visible") == false then
    outputDebugString("hud hidden")
end
```

### Note

The data never reaches the server or the other clients, whatever `sync` says.

## See also

- [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.
- [getElementData (Shared)](https://wiki.mymp.gg/en/getElementData.md): Reads a value stored on an element.
- [removeElementData (Shared)](https://wiki.mymp.gg/en/removeElementData.md): Deletes a piece of data kept on an element.
- [onClientElementDataChange (Client)](https://wiki.mymp.gg/en/onClientElementDataChange.md): Fired when a piece of an element's data changes or is removed. Cancelling the event does not undo the change: this client's data keeps the new value.
