- Documentation
- Client functions
- playSound
Function
playSound
Plays an MP3 or WAV file from a resource with no position in the world (it sounds the same everywhere). The file must be listed in meta.xml as a <file>.
Syntax
sound playSound(string soundPath [, bool looped = false, bool throttle])Arguments
soundPathstring- A path in the resource or
:resource/file.mp3. Web addresses are not supported. loopedbool, optional = false- Whether to loop.
throttlebool, optional- Accepted for compatibility with existing scripts, but the game does not use it.
Returns
A sound element or false (the reason is written to the debug log).
Example
local music = playSound("audio/menu.mp3", true)
setSoundVolume(music, 0.5)
addEventHandler("onClientPlayerSpawn", localPlayer, function()
if isElement(music) then
stopSound(music)
end
end)
<meta>
<script src="client.lua" type="client" />
<file src="audio/menu.mp3" />
</meta>
See also
playSound3DPlays a sound at a point in the world. It fades with distance from the camera: full volume up to 5 m, silent from 20 m. It is panned left-right.stopSoundStops a sound and removes it. FiresonClientSoundStoppedwith the reason"destroyed".setSoundVolumeSets the sound volume.1is normal, up to2amplifies.onClientSoundStoppedA sound stopped playing (it ended, was stopped or was destroyed).