# getSafePedSpawnPosition (Client)

> Picks a random spot on a footpath near a point where a ped can appear, the way SA chooses where to create peds. The spot is on the ground.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Roads and paths
- **URL**: https://wiki.mymp.gg/en/getSafePedSpawnPosition-client
- **Counterpart**: Also exists on the server, with its own implementation: [getSafePedSpawnPosition (Server)](https://wiki.mymp.gg/en/getSafePedSpawnPosition-server.md)

## Syntax

```lua
vec3|false getSafePedSpawnPosition(float x, y, float minDistance, float maxDistance [, float minOffScreen = minDistance, float maxOffScreen = maxDistance])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `x, y` | `float` | The point to search around. |
| `minDistance` | `float` | The least distance from the point, in metres, for a spot that is visible on screen. |
| `maxDistance` | `float` | The most distance from the point for a spot that is visible on screen. |
| `minOffScreen` | `float` | The least distance for a spot off screen. *(default: `minDistance`)* |
| `maxOffScreen` | `float` | The most distance for a spot off screen. *(default: `maxDistance`)* |

## Returns

The spot's position, or `false` if no spot worked.

## Example

```lua
local position = getElementPosition(localPlayer)
local spot = getSafePedSpawnPosition(position.x, position.y, 40, 60, 20, 60)
if spot then
    createPed("male01", spot.x, spot.y, spot.z)
end
```

### Note

It only searches the path area (750 m wide) that holds the point, and that area must be loaded. The result is random: the same call gives different spots, and one may fail where another succeeds.

## See also

- [getRoadDensity (Shared)](https://wiki.mymp.gg/en/getRoadDensity.md): Measures how much road there is around a point: the lanes times the length of the car links starting within 80 m of it, scaled down.
- [createPed (Client)](https://wiki.mymp.gg/en/createPed-client.md): Creates a ped that exists on this client only.
- [getPathNodesInRadius (Shared)](https://wiki.mymp.gg/en/getPathNodesInRadius.md): Lists the road or footpath nodes within a radius.
