# destroyElement (Shared)

> Destroys an element and all of its children. Before it goes, each one fires `onElementDestroy` on the server or `onClientElementDestroy` on the client.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Elements
- **URL**: https://wiki.mymp.gg/en/destroyElement

## Syntax

```lua
bool destroyElement(element element)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | The element to destroy. |

## Returns

`true` if it was destroyed. `false` if the element is already being destroyed or cannot be destroyed.

The root, resources, the console and players cannot be destroyed. On a client, neither can elements that came from the server.

## Example

```lua
local marker = createElement("checkpoint")
setTimer(destroyElement, 10000, 1, marker)
```

## See also

- [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.
- [isElement (Shared)](https://wiki.mymp.gg/en/isElement.md): Tells whether a value is an element that still exists.
- [onElementDestroy (Server)](https://wiki.mymp.gg/en/onElementDestroy.md): Fired when an element is about to be destroyed, while it still exists.
- [onClientElementDestroy (Client)](https://wiki.mymp.gg/en/onClientElementDestroy.md): Fired when an element is about to be destroyed, while it still exists.
