Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Stopping sounds before adding to debris ?

function Fire_Gun()	
	if FireSound then
	local ff = Instance.new("Sound")
	local bb = Instance.new("Sound")
	bb.SoundId =""
	ff.SoundId =""
	bb.Volume = 1
	ff.Volume = 1
	bb.Pitch = 1
	ff.Pitch = 1
	bb.Parent = script.Parent.Handle
	ff.Parent = script.Parent.Main
	bb:Play()	
	ff:Play()
	game:GetService("Debris"):addItem(bb,1.3) --here 
	game:GetService("Debris"):addItem(ff,5) -- & here

This script is just from my gun no need to fix anything here just a question on the last 2 lines when my gun fires adds alot of sounds it's good and then adds to debris them, but first i want them to stop the sound and THEN add it to debris, cuz if it doesn't stop before added to debris it still plays the sound so how can i fix that ?

P.S i removed the soundids cuz don't want to show them.

AND NO the wait can't be added it will make the gun delay shoot to the time u put wait()

1 answer

It's quite easy, First off, figure out the length in seconds of the audio file or how long you want the gun shot to last, use wait(time) to wait the time that you want the shot to last instead of using the Debris wait time system, then use :Stop() on every sound that you want to stop. Something like this.

wait(1.3)
bb:Stop()
game:GetService("Debris"):addItem(bb, 0)
wait(5-1.3) --Change this to five if you want to wait actual five seconds.
ff:Stop()
game:GetService("Debris"):addItem(ff, 0)

Hope this helps! If it dosen't work, comment please.

2 comments

0

No u cannot add the wait because it makes the gun shoot in that delay what wait is

0

@Bulvyte Debris uses pretty much the same wait system, and I'm pretty sure there's no ItemAddedToDebris event to hook to. But I will look into other options.

This discussion is preserved as it was. New answers, comments, and votes are closed.