Sounds

Trigger sounds for players from server scripts.

All sounds are played through koja-lib's NUI page. See Client Sounds for details on file sources and NUI URLs.

PlaySoundForSource

Play a sound for a specific player.

exports['koja-lib']:PlaySoundForSource(source, file, volume, soundId, loop)
Parameter
Type
Description

source

number

Player server ID

file

string

Short sound name or full NUI URL

volume

number?

Volume 0.0 – 1.0 (default: 0.5)

soundId

string?

ID for stopping later

loop

boolean?

Loop the sound (default: false)

PlaySoundForAll

Play a sound for every connected player.

exports['koja-lib']:PlaySoundForAll(file, volume, soundId, loop)

PlayDistanceSound

Play a sound for all players within dist metres of coords. Volume fades with distance.

Parameter
Type
Description

coords

vector3

Origin of the sound

dist

number

Maximum hearing radius (max 250 m)

file

string

Short sound name or full NUI URL

volume

number?

Base volume at origin

soundId

string?

ID for stopping later

loop

boolean?

Loop

StopSoundForAll

Stop a looping sound for all players.

Examples

Play alert for one player

Looping heist alarm for everyone

Distance-based explosion from another resource

Using sounds from another resource

The other resource just needs the file declared in its fxmanifest.lua:

Then trigger with the full NUI URL:

Net Events (alternative)

Last updated