# detachElements (Compartilhado)

> Solta um elemento do elemento em que está anexado. Ele fica onde está.

- **Plataforma**: MY Multiplayer (MYMP)
- **Tipo**: Função Lua
- **Lado**: Compartilhado
- **Categoria**: Anexos
- **URL**: https://wiki.mymp.gg/pt/detachElements

## Sintaxe

```lua
bool detachElements(element element [, element target = nil])
```

## Parâmetros

| Nome | Tipo | Descrição |
| --- | --- | --- |
| `element` | `element` | O elemento a soltar. |
| `target` | `element` | Se for passado, só solta quando o elemento estiver anexado a este alvo. *(padrão: `nil`)* |

## Retorno

`true` se soltou. `false` se o elemento não estava anexado, se `target` foi passado e não é o alvo atual, ou se `onElementDetach` foi cancelado.

## Exemplo

```lua
addCommandHandler("soltar", function(player)
    local target = getElementAttachedTo(player)
    if target then
        detachElements(player, target)
    end
end)
```

## Veja também

- [attachElements (Compartilhado)](https://wiki.mymp.gg/pt/attachElements.md): Pendura um elemento em outro. A partir daí ele segue o alvo até ser solto.
- [isElementAttached (Compartilhado)](https://wiki.mymp.gg/pt/isElementAttached.md): Diz se um elemento está anexado a outro.
- [getElementAttachedTo (Compartilhado)](https://wiki.mymp.gg/pt/getElementAttachedTo.md): Diz em qual elemento um elemento está anexado.
- [onElementDetach (Servidor)](https://wiki.mymp.gg/pt/onElementDetach.md): Disparado antes de um elemento ser solto no servidor, por detachElements ou por attachElements levando-o para outro alvo. Cancelar o evento mantém o elemento anexado.
