A better way to play one off sounds

e.g. Bullet firing, potion exploding, etc

Things that will never be played again or need to be played multiple times at once.

Example solution:

SoundService:Play( SoundId, Pos or Part, Pitch, etc )

5 Likes

You could make your own function like me:

_G.PlayLocalSound = function(soundId, volume, pitch)
	coroutine.resume(coroutine.create(function()
		local sound = Instance.new('Sound', player.PlayerGui)
		sound.SoundId = soundId
		sound.Volume = volume or 0.5
		sound.Pitch = pitch or 1
		sound:Play()
		sound:Destroy()
	end))
end

Doesn’t currently allow for sounds played from parts but you could add arguments to it to make it happen. And this is only for local sounds, not things that other players would hear.

This can already be done with current APIs and I can’t think of many reasons you would only want to play a sound once.

Gun fire would be played every time the gun is shot, why would you want to have to download the sound again each time you play it? Or is it some crazy use case where the gun can only be shot once and never again? I don’t really understand this at all.

Playing a sound multiple times does not download it again. ROBLOX saves the sound the first time it is downloaded.

According to

it seems that this request does not suggest that the sound will only ever be played once, but that it is an individual, single sound that does not need playback control. I believe the current or new behavior for sounds will be to not have them playing more than once for a single Sound Instance, but I’m not sure. That means you cannot have a single gunshot sound effect and call :Play() every time because, it won’t play multiple shots at once if you are firing quickly.

Personally, I don’t like this suggestion. It can easily be done with the current API. Make a new Sound object, apply your properties, parent it to an existing part or a new one to set its position. Something like what @MarkMcBlox said works perfectly for this.

2 Likes

Not a fan of this even though it has been brought up a couple of times, since it can be done with a simple lua function (you don’t even need to use coroutines, just something like wait for destroying the sound will work).

1 Like

I would love a revamped Debris:AddItem() system. Something that reliably destroys an object after x seconds, since AddItem() does not use Destroy()

Otherwise, there are checks in place you have to do to reliably destroy an item after x seconds. Such as, does the item still exist? What if you want code to run right after creating the object, then you’d have to put that wait in a coroutine or spawn.

I thought AddItem does use Destroy now?

1 Like

According to the wiki it does

“The Debris service will remove the object in the same manner the Destroy method does.”

1 Like