# Server

{% hint style="danger" %}

#### If you don't pass -1 to source, sound will not be saved on the server side. So there will be no sync.

{% endhint %}

### Play

{% code fullWidth="false" %}

```lua
local soundId = exports['mx-surround']:Play(source, soundId, url, coords, loop, volume, panner)
```

{% endcode %}

This export is a synchronous function, which means that this code returns a soundId to you. And if sound is not created, it returns false

#### Parameters

* > **source**: `number`
  >
  > * You can pass -1 for sync
* > **soundId?**: `string`
  >
  > * If not provided, will be created automatically
* > **url**: `string`
* > **coords**: `vector3`
  >
  > * Unlike the client side the coords param is required on the server side
* > **loop?:** `boolean`
* > **volume?:** `number`
  >
  > * Override default volume (even if sound profile is enabled)
* > **panner?:** `PannerNode`
  >
  > * [See how to use](https://developer.mozilla.org/en-US/docs/Web/API/PannerNode?retiredLocale=tr)

#### Returns

* > **`soundId | false`**

***

### Play Async

```lua
local soundId = exports['mx-surround']:PlayAsync(source, soundId, url, coords, loop, volume, panner, data)
```

This export does not return the soundId compared to the above. However, it works faster and you can connect the sound directly to an entity or player at startup. Very useful for asset sounds

{% hint style="danger" %}
It should only be used for asset sounds, **DO NOT** use it for youtube, spotify and soundcloud!
{% endhint %}

#### Parameters

* > **source**: `number`
  >
  > * You can pass -1 for sync
* > **soundId?**: `string`
  >
  > * If not provided, will be created automatically
* > **url**: `string`
* > **coords**: `vector3`
  >
  > * Unlike the client side the coords param is required on the server side
* > **loop?:** `boolean`
* > **volume?:** `number`
  >
  > * Override default volume (even if sound profile is enabled)
* > **panner?:** `PannerNode`
  >
  > * [See how to use](https://developer.mozilla.org/en-US/docs/Web/API/PannerNode?retiredLocale=tr)
* > **data?:** `{ attachEntity: number, attachPlayer: number }`

***

### Stop

{% hint style="info" %}
The difference from Pause export is this: If you are playing a song on spotify or youtube, it completely deletes the player so that there is no player in the dom. This is very important for optimization
{% endhint %}

```lua
exports['mx-surround']:Stop(source, soundId)
```

#### Parameters

* > **source:** `number`
* > **soundId:** `string`

***

### Pause

```lua
exports['mx-surround']:Pause(source, soundId)
```

#### Parameters

* > **source:** `number`
* > **soundId:** `string`

***

### Resume

```lua
exports['mx-surround']:Resume(source, soundId)
```

#### Parameters

* > **source:** `number`
* > **soundId:** `string`

***

### Destroy

```lua
exports['mx-surround']:Destroy(source, soundId)
```

**Parameters**

* > **source:** `number`
* > **soundId:** `string`

***

### Destroy All

```lua
exports['mx-surround']:destroyAllSounds()
```

***

### Attach Entity

```lua
exports['mx-surround']:attachEntity(source, soundId, networkId)
```

#### Parameters

* > **source:** `number`
* > **soundId:** `string`
* > **networkId:** `number`

***

### Detach Entity

```lua
exports['mx-surround']:detachEntity(source, soundId)
```

#### Parameters

* > **source:** `number`
* > **soundId:** `string`

***

### Attach To Player

{% hint style="info" %}
If you are going to attach to a player, you can of course use the `attachEntity`. **But you should definitely use this**. Because if the player gets in the car, the script detects it with this export and filters the sound.
{% endhint %}

```lua
exports['mx-surround']:attachPlayer(source, soundId, playerId)
```

#### Parameters

* > **source:** `number`
* > **soundId:** `string`
* > **playerId:** `number`

***

### Detach From Player

```lua
exports['mx-surround']:detachPlayer(source, soundId)
```

#### Parameters

* > **source**: `number`
* > **soundId:** `string`

***
