# playSound3D (Client)

> Plays a sound at a position in the world, on this client only. Its volume falls with distance between `setSoundMinDistance` (5 m) and `setSoundMaxDistance` (20 m). Fires `onClientSoundStarted` with `play`.

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

## Syntax

```lua
sound|false playSound3D(string sound, float x, y, z [, bool looped = false, bool throttled = true])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `sound` | `string` | A name registered with `engineAddSound`, the path of a file in the resource (`@other/file.mp3` for another resource) or the bytes of an audio file themselves. |
| `x, y, z` | `float` | The sound's position in the world, as three numbers or one `vec3`. |
| `looped` | `bool` | Play the sound again from the start when it reaches the end. *(default: `false`)* |
| `throttled` | `bool` | Accepted for MTA compatibility and ignored. *(default: `true`)* |

## Returns

The created `sound` element, or `false` if the sound could not be opened.

The sound streams out (`onClientElementStreamOut`) when the camera is more than 40 m beyond its max distance or in another dimension, and streams back in (`onClientElementStreamIn`) within 20 m of it.

## Example

```lua
local pos = getElementPosition(localPlayer)
local radio = playSound3D("sounds/radio.ogg", pos, true)
setSoundMaxDistance(radio, 40)
```

### Coming from MTA

Internet addresses (`http`, `ftp`) are not accepted. Another resource is named with `@resource/`, not `:resource/`.

## See also

- [playSound (Client)](https://wiki.mymp.gg/en/playSound-client.md): Plays a sound with no position in the world, on this client only. Fires onClientSoundStarted with the reason play.
- [setSoundMaxDistance (Shared)](https://wiki.mymp.gg/en/setSoundMaxDistance.md): Sets the distance at which a 3D sound goes silent. The default is 20 m. On the server, the change is sent to every client.
- [setSoundSpeaker (Client)](https://wiki.mymp.gg/en/setSoundSpeaker.md): Has a ped speak a sound: its mouth moves with the sound's level and, if the sound is 3D, it comes from the ped's head every frame.
- [playSound3D (Server)](https://wiki.mymp.gg/en/playSound3D-server.md): Creates a sound at a position in the world that every client plays together. Changes made to it on the server reach everyone.
