onClientSoundStopped
ClientEvent
Fired when a sound stops playing on this client: paused, stopped or finished.
addEventHandler("onClientSoundStopped", root, function(string reason) … end)
Handler parameters
| Name | Type | Description |
|---|---|---|
| reason | string | paused when it is paused, destroyed when stopSound stops it, finished when it reaches its end. |
Source
The sound element.
With finished, a sound of this client is destroyed right after. A server sound keeps existing until the server removes it.
Example
local playlist = { "music/1.mp3", "music/2.mp3", "music/3.mp3" }
local current = 1
local function playNext()
local sound = playSound(playlist[current])
addEventHandler("onClientSoundStopped", sound, function(reason)
if reason == "finished" then
current = current % #playlist + 1
playNext()
end
end)
end
playNext()