# getNthClosestPathNode (Shared)

> Finds the nth road or footpath node closest to a point.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Roads and paths
- **URL**: https://wiki.mymp.gg/en/getNthClosestPathNode

## Syntax

```lua
int, vec3|false getNthClosestPathNode(float x, y, z, int n [, string type = car, bool water = false])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `x, y, z` | `float` | The point to search from. |
| `n` | `int` | Which node: 1 is the closest, 2 the next one, and so on. Below 1 raises an error. |
| `type` | `string` | `car` for roads, `ped` for footpaths. *(default: `car`)* |
| `water` | `bool` | `true` searches only the boat paths on water; `false`, only on land. *(default: `false`)* |

## Returns

The node's id and its position, or `false` if there are not that many nodes.

## Example

```lua
local position = getElementPosition(localPlayer)
for n = 1, 5 do
    local node = getNthClosestPathNode(position.x, position.y, position.z, n)
    if not node then
        break
    end
    outputDebugString(("node %d: %d"):format(n, node))
end
```

### Note

Only nodes in loaded path areas count: those near the player, or requested with `requestPathNodesInArea`.

## See also

- [getClosestPathNode (Shared)](https://wiki.mymp.gg/en/getClosestPathNode.md): Finds the road or footpath node closest to a point.
- [getPathNodesInRadius (Shared)](https://wiki.mymp.gg/en/getPathNodesInRadius.md): Lists the road or footpath nodes within a radius.
