# onClientElementDetach (Client)

> Fired before an element is detached by a client script, by `detachElements` or by `attachElements` moving it to another target. Cancelling the event keeps the element attached.

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

## Syntax

```lua
addEventHandler("onClientElementDetach", root, function(element detachedFrom, float x, y, z, float rx, ry, rz) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `detachedFrom` | `element` | The element it hangs on. |
| `x, y, z` | `float` | The element's world position at that moment. |
| `rx, ry, rz` | `float` | The element's rotation at that moment. |

## Source

The element about to be detached.

When the target is destroyed, the elements hanging on it are detached without firing this event. If the event is cancelled during an `attachElements` to another target, that `attachElements` returns `false`.

## Example

```lua
addEventHandler("onClientElementDetach", root, function(detachedFrom, x, y, z)
    outputDebugString(("%s detached at %.1f, %.1f, %.1f"):format(getElementType(source), x, y, z))
end)
```

## See also

- [detachElements (Shared)](https://wiki.mymp.gg/en/detachElements.md): Detaches an element from the element it hangs on. It stays where it is.
- [onClientElementAttach (Client)](https://wiki.mymp.gg/en/onClientElementAttach.md): Fired when a client script calls attachElements, before the element is attached. Cancelling the event stops the attachment and makes attachElements return false.
- [attachElements (Shared)](https://wiki.mymp.gg/en/attachElements.md): Hangs one element on another. From then on it follows the target until it is detached.
