# onClientObjectDamage (Client)

> Fired on this client before an object takes damage. Cancelling the event prevents the damage.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Client
- **Category**: Objects
- **Cancellable**: `cancelEvent`
- **URL**: https://wiki.mymp.gg/en/onClientObjectDamage

## Syntax

```lua
addEventHandler("onClientObjectDamage", root, function(float loss, element|nil attacker) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `loss` | `float` | The health the object will lose, already multiplied by its model's `colDamageMult`. It can be more than the health it has. |
| `attacker` | `element\|nil` | The player, ped, vehicle or object that caused the damage, or `nil` if there is none (as with `breakObject`). |

## Source

The object about to take the damage.

Only objects created by scripts have this event: the map's own objects are not elements. Any damage counts, whether a shot, a collision, an explosion or `breakObject`.

Each client works out the damage on its own, so cancelling applies to this client alone. In the handler, `breakObject` on an object that `breakObject` is already breaking returns `false`, and destroying the object with `destroyElement` is safe.

## Example

```lua
addEventHandler("onClientObjectDamage", root, function(loss, attacker)
    if attacker == localPlayer then
        cancelEvent()
    end
end)
```

## See also

- [breakObject (Shared)](https://wiki.mymp.gg/en/breakObject.md): Breaks a breakable object at once.
- [getElementHealth (Shared)](https://wiki.mymp.gg/en/getElementHealth.md): Reads the health of a player, ped, vehicle or object.
- [onClientPlayerWeaponFire (Client)](https://wiki.mymp.gg/en/onClientPlayerWeaponFire.md): Fired on this client after a player fires a shot, whether the local player or another one this client sees.
- [createObject (Client)](https://wiki.mymp.gg/en/createObject-client.md): Creates an object that exists on this client only.
