# onClientElementDataChange (Client)

> 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.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Client
- **Category**: Elements
- **URL**: https://wiki.mymp.gg/en/onClientElementDataChange

## Syntax

```lua
addEventHandler("onClientElementDataChange", root, function(string key, any oldValue, any newValue) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `key` | `string` | The data's name. |
| `oldValue` | `any` | The previous value, or `nil` if the key did not exist. |
| `newValue` | `any` | The new value, or `nil` if the data was removed. |

## Source

The element whose data changed.

It also fires when data synced by the server arrives.

## Example

```lua
addEventHandler("onClientElementDataChange", localPlayer, function(key, oldValue, newValue)
    if key == "money" then
        outputDebugString("money: " .. tostring(oldValue) .. " -> " .. tostring(newValue))
    end
end)
```

## See also

- [setElementData (Client)](https://wiki.mymp.gg/en/setElementData-client.md): Keeps a piece of data on an element, on this client only.
- [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.
