ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. playSound

Function

playSound

ClientSound (client)Identical to MTA:SA

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)

See also