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

How To Add In A Wait Before The Sound Play Again?

Can somebody help me add in a wait? When I touch the brick, the sound play and it work but I don't want someone to just keep touching the brick over and over without waiting for a second or so to make the sound play again. It also lag too and I don't know why...

script.Parent.Touched:connect(function()
	script.Parent.Sound:Play()
end)

1 answer

✓ Accepted answer

Use a debounce.

This is simple. We're just going to make a bool variable, and if the variable is true, then we play the sound and make the variable false, wait a while, and make it true again.

Example,

local Debounce = true
script.Parent.Touched:connect(function()
	if Debounce then
		Debounce = false
		script.Parent.Sound:Play()
		wait(5)-- Wait As long as you want
		Deounce = true
	end
end)

Good Luck!

If I helped, please don't forget to accept my answer.

2 comments

0

Thank you so much! ;)

0

np

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