Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Ended event not working as it should... What's going on here?

Asked by 5 years ago

Okay, so I made a custom sound system that I made wait until the sound has finished playing using http://wiki.roblox.com/index.php?title=API:Class/Sound/Ended and the event only fires when the sound has finished playing... When the event is also supposed to be fired when :Stop() is called on the sound (it even says it in the wiki)... But when I call :Stop() on the sound the event isn't fired... And no it's not my script because it stopped playing the sound just fine. Is there something I'm doing wrong?... Why isn't this event working properly?

I need this event to also fire when :Stop() is called so I can skip a sound that's currently playing without my script breaking.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

If the .Ended event doesn't work for you, you should use both .Ended and .Stopped events to tell whenever the audio stops or ends. Here's how you would use 2 events maybe:

local sound = script.Parent
local function audioStops(audioId)
    -- insert your script stuff here
end

sound.Ended:Connect(audioStops)
sound.Stopped:Connect(audioStops)

(Edit to answer comment below about making multiple events)

There's not such a great way of adding multiple events. The best way I can think of with waiting for both events with using :Wait() is:

local sound = script.Parent
local b = false
delay(0, function() -- This makes it so the script doesn't yield while running this function.
    sound.Ended:Wait()
    b = true
end)
delay(0, function()
    sound.Stopped:Wait()
    b = true
end)
while true do
    wait()
    if b then
        -- insert script stuff
    end
end
0
This works BUT for some reason doing it like this breaks my script... It makes my script forget to repeat... Is there a way I could wait until either one of those events are fired? Because me doing `sound.Ended:Wait()` works on my script and it repeats itself 3ggRoll 0 — 5y
0
Answered in edited answer. fighter169mobile 123 — 5y
Ad

Answer this question