I’ve been having a lot of issues with PlayLocalSound().
This LocalScript demonstrates the first issue that I have discovered:
local SoundService = game:GetService("SoundService")
task.wait(5) -- script is in StarterCharacterScripts
print("activated")
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9114430253"
sound.Looped = false -- did not resolve the issue
SoundService:PlayLocalSound(sound)
sound.Ended:Wait()
print("ended")
Ended:Wait() will yield forever - “ended” is never printed. I believe Ended is supposed to fire for PlayLocalSound usage too, as shown in the documentation: SoundService:PlayLocalSound
Here is the reproduction file for this specific issue:
PlayLocalSound_IssueDemo.rbxl (34.3 KB)
However, there are more issues that I discovered while trying to come up for a solution for the above problem. These can be very easily reproduced rather than me providing steps/files for each, so please confirm you can replicate them… all of these bugs arise from sound instances played using PlayLocalSound:
- Adding sound:Stop() does not stop the sound (when played with PlayLocalSound)
- I tried using sound:Destroy() as a workaround, but this also doesn’t work.
- Changing the volume property of the sound instance does not do anything (when played with PlayLocalSound).
-
sound.TimeLength is always equal to zero (another property not working).
- The Sound.TimeLength documentation says that this zero value is due to the sound instance not being loaded. However…
- Waiting for the sound to load - Loaded:Wait() - (as shown in the Sound.TimeLength documentation) causes an infinite yield too. In other words, the Loaded event is not firing, in the same way that the Ended event is not firing in the first issue above.
(Given that I only found these other issues while trying to solve the first issue, there is very likely more bugs than the ones detailed above. The bugs above all relate to different things: e.g. events not firing, sound properties having incorrect values, and functions such as Stop() not working - and even Destroy() [on sound instances played with PlayLocalSound].)
These are things that I tried to resolve the first issue, but they did not work:
- Setting Looped to false
- Connecting Ended to a function rather than using Wait() (does not fire still)
- Using the Stopped event instead of Ended (does not fire either)
- Doing wait(sound.TimeLength) also isn’t working as an alternative solution. This is due to the issue described above: TimeLength is always 0.
My post in Scripting Support demonstrates the original use case where I discovered this bug: PlayLocalSound() issues - e.g. Ended not firing - engine bug or incorrect usage? Alternatives for playing sounds locally?
All issues described in it have been described in this report in more detail.
Many thanks in advance!
EDIT: I have come across two other posts with related issues in Scripting Support: How to stop a sound played with SoundService:PlayLocalSound(sound)? and UI SFX not destroying with Sound Destroy()