AudioPlayer is "debounced"

When :Play() is called repeatedly on the same AudioPlayer instance within a short period, playback appears to be internally debounced. For example, when :Play() is called every 0.1 seconds, some calls do not produce any audible playback. A practical use case is a hover sound connected to MouseEnter for multiple GUI buttons. When moving the cursor quickly between buttons, :Play() is called for every hover event, but the sound only plays intermittently. The previous Sound instance handled this reliably: the hover sound played every time, regardless of how quickly the cursor moved between buttons.

This is particularly frustrating because I have already converted a significant portion of my game’s architecture to use the new AudioPlayer instance instead of the legacy Sound instance. If this behaviour is an intentional limitation, I would need to spend additional development time reverting those systems back to Sound unnecessarily.

Expected behavior

I expect audible playback to be produced everytime :Play() is called on the AudioPlayer instance no matter the frequency, just like how the original sound instance is.

1 Like

Hey @ThoseNamesAreGood – the Sound API has 4 methods, Play/Resume/Pause/Stop. The way Play() behaves is that it rewinds to the last TimePosition that you’ve set (typically 0) before playing.

So even if the Sound were already playing, calling :Play() on it again would rewind and replay.

That implicit rewind behavior has been tricky to support (led to some bugs over the years where Sound rewinds to the wrong time), so AudioPlayer took a different approach: It only has two methods, Play/Stop, and they don’t alter the TimePosition (so they behave more like Sound:Resume()/Sound:Pause()).

In order to implement the same replay behavior, you could replace any code that calls :Play() with

audioPlayer:Stop()
audioPlayer.TimePosition = 0
audioPlayer:Play()
2 Likes

Really appreciate the response, thanks

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