I’ve been having a lot of issues with PlayLocalSound().
local tool = script.Parent
local SoundService = game:GetService("SoundService")
local function onActivated()
print("activated")
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://10088482556"
sound.Looped = false -- this did not resolve any issues
SoundService:PlayLocalSound(sound)
sound.Ended:Wait()
print("ended")
end
tool.Activated:Connect(onActivated)
For example, in the function above, Ended:Wait() will yield forever - “ended” is never printed. I believe Ended is supposed to fire for PlayLocalSound usage too, as shown here: SoundService:PlayLocalSound.
- What is causing this?
- Is there a different way of checking if the local sound has ended? (see attempted solutions below)
- If not, is there an alternative to playing sounds on the client which does not involve PlayLocalSound()?
I have tried:
- Setting Looped to false
- Connecting Ended to a function (does not fire still)
- Using Stopped instead (does not fire either)
- Doing wait(sound.TimeLength) also isn’t working as an alternative solution. This is due to another issue: TimeLength is always 0.
- Sound.TimeLength says that this zero value is due to the sound not being loaded. However, ANOTHER issue is that waiting for the sound to load (as shown in the documentation) causes an infinite yield too.
Other issues:
- sound:Stop() does not stop the local sound
- Tried using sound:Destroy() as a workaround, but this also doesn’t work.
- Don’t think changing the sound volume works either.
- TimeLength 0 value and Loaded:Wait() infinite yield (as mentioned above)
If my usage is correct and other people can replicate this issue then I guess I will post this in bug reports.
Many thanks in advance.