Option for sounds to play multiple times at once

As a Roblox developer, it is currently too hard to efficiently play a singular sound multiple times without the sound to restart each time you play it.

Case example:
At the moment, instead of being able to do something like

function onPunchLand()
    PunchSound:Play()
end

I’m forced to do something like

function onPunchLand()
    local soundToPlay = PunchSound:Clone()
    soundToPlay.Parent = PunchSound.Parent
    soundToPlay:Play()
    soundToPlay.Ended:Wait()
    soundToPlay:Destroy()
end

You either have to create entire new sound objects every time, or you have to come up with some sort of sound cache system. Creating entirely new sound object every time probably adds up if there are a lot of sounds being frequently played.

If Roblox is able to address this issue, it would improve my development experience because I wouldn’t have to worry about the inefficiencies of creating an entirely new sound instance just to make sure the sound plays from start to finish.

3 Likes

The cost of creating a few instances is probably insignificant compared to the cost for the engine to play X audio tracks in pararallel, and that happens in either case. You may as well create the additional instances and just delete them after. Efficiency is not a good argument here – the instances themselves are pretty cheap.

Alternatively you can use SoundService | Documentation - Roblox Creator Hub if the sounds are short for convenience, that way you should be able to reuse the same instance. (this also works for 3D sounds but they won’t move / have doppler effect / etc while the sound is playing, which is why it’s only useful for short sounds)

2 Likes

Huh
I guess there are better engine features to work on if the cost of creating sound instances is relatively insignificant. I just figured it might be impactful in large quantities/production.

Hi @dispeller!

I currently use SoundSprites and so I have to create a lot of Sound Instances to play SFXs, I haven’t had any issues so far so you shouldn’t be worried as buildthomas said is it insignificant.

Also when would you need more than 20 or even 10 SFXs playing at once? Probably never, but let me know if you do.

Furthermore it would cause a lot of problems to play a sound multiple times on the same Instance, it would be a mess, what happens to .Played and how many times do I have to call :Stop()?

1 Like