# getElementByID (Compartido)

> Busca el primer elemento con un ID, a partir de un elemento y bajando por sus hijos.

- **Plataforma**: MY Multiplayer (MYMP)
- **Tipo**: Función Lua
- **Lado**: Compartido
- **Categoría**: Elementos
- **URL**: https://wiki.mymp.gg/es/getElementByID

## Sintaxis

```lua
element|nil getElementByID(string id [, element startAt = root])
```

## Parámetros

| Nombre | Tipo | Descripción |
| --- | --- | --- |
| `id` | `string` | ID buscado. |
| `startAt` | `element` | Dónde empieza la búsqueda. Él mismo también cuenta. *(por defecto: `root`)* |

## Retorno

El elemento encontrado, o `nil` si ninguno tiene ese ID.

## Ejemplo

```lua
local gate = getElementByID("lspd_gate", resourceRoot)
if gate then
    moveObject(gate, 3000, 1544.7, -1630.7, 10)
end
```

## Ver también

- [getElementID (Compartido)](https://wiki.mymp.gg/es/getElementID.md): Lee el ID de un elemento, el nombre que busca getElementByID.
- [setElementID (Compartido)](https://wiki.mymp.gg/es/setElementID.md): Da un id (nombre) a un elemento, para encontrarlo después con getElementByID.
- [getElementsByType (Servidor)](https://wiki.mymp.gg/es/getElementsByType-server.md): Lista todos los elementos de un tipo debajo de un elemento del árbol en el servidor.
