> For the complete documentation index, see [llms.txt](https://docs.moxha.dev/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.moxha.dev/documentation/paid-scripts/surround-spatial-audio/api/server/handlers.md).

# Handlers

These are handlers

#### Play Error

```lua
exports['mx-surround']:onPlayError(soundId, function(info, reason)
    -- skip to the next track for everyone
end)
```

Triggered once per track when the track itself is broken, not just one player's copy of it:

* No player could start it at all, or
* Half of the players in range report it failing while it plays

One region-locked player in a full room will not trigger it. You can register it before `Play`, so a track that never starts is caught too.

{% hint style="info" %}
`reason` is the error the client reported: a YouTube error code and what it means, a media error, or a timeout.
{% endhint %}

**Parameters**

* **soundId**: `string | number`
* **fn**: `function(info: table, reason: string)`

***

#### Error

```lua
exports['mx-surround']:onError(soundId, function(info, reason) end)
```

Triggered every time a single player could not play a synced sound. `info.lastError` holds `{ player, reason }`.

**Parameters**

* **soundId**: `string | number`
* **fn**: `function(info: table, reason: string)`

***

#### Play End

```lua
exports['mx-surround']:onPlayEnd(soundId, fn)
```

**Parameters**

* **soundId**: `string | number`
* **fn**: `function`

***

#### Destroy

```lua
exports['mx-surround']:onDestroy(soundId, fn)
```

**Parameters**

* **soundId**: `string | number`
* **fn**: `function`
