# onElementDestroy (Server)

> Fired when an element is about to be destroyed, while it still exists.

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

## Syntax

```lua
addEventHandler("onElementDestroy", root, function() ... end)
```

## Source

The element about to be destroyed.

When an element is destroyed, its children are destroyed before it, and each fires its own event.

## Example

```lua
local blips = {}

addEventHandler("onElementDestroy", root, function()
    blips[source] = nil
end)
```

## See also

- [destroyElement (Shared)](https://wiki.mymp.gg/en/destroyElement.md): Destroys an element and all of its children. Before it goes, each one fires onElementDestroy on the server or onClientElementDestroy on the client.
- [createElement (Shared)](https://wiki.mymp.gg/en/createElement.md): Creates an element of a type the script makes up, with nothing in the world. It goes under the resource's dynamic element root.
- [onClientElementDestroy (Client)](https://wiki.mymp.gg/en/onClientElementDestroy.md): Fired when an element is about to be destroyed, while it still exists.
