Multiple bugs w/ PlayLocalSound() - sound instances have incorrect properties, events not firing, & functions such as Stop() and Destroy() don't work

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()

First of all, you should be using Play on the sound instance rather than PlayLocalSound, the latter is used for Studio plugins rather than in-game sounds.

This is likely intentional, sounds started with PlayLocalSound cannot be stopped.

Thank you for bringing this up – the current documentation looks misleading, so we’ll work on getting that corrected.

SoundService:PlayLocalSound operates by creating a “detached” copy of the sound’s playback, similar to using the PlayOnRemove property. By detached, I mean that it has no accompanying Instance.

For triggering oneshot “fire and forget” sound effects, which might need to be played many times at once, it can be cumbersome to clone, play, and manage all those Sounds – that’s really where this API shines.

But, since the playback is actually a detached copy, changing properties of the original instance after the copy has been made will not have any effect.

If your script needs to control Sound properties or connect to events after playing it, I would recommend cloning the sound, playing the clone, and then Destroying the clone

11 Likes

Interesting. Is that why SoundGroups/SoundEffects don’t work with :PlayLocalSound()?

Perfect.
I saw them stacking up in my Players.RBellev and was concerned. Now I don’t have to worry.

I guess since there’s no accompanying instance, should I remove the .Parent for them?

Actually, we flipped a flag about a week ago to fix that specific problem, so they should incorporate effects & SoundGroups now! But you are correct – previously, the detached copies were not correctly copying child effects or the SoundGroup property.

3 Likes

The original Sound’s Parent still informs whether the playback will be 2d or 3d – and if 3d, where it will be heard from. So .Parent might still matter for your use-case

2 Likes

This topic was automatically closed after 14 days. New replies are no longer allowed.