While walking on it, it keeps firing again and the sound keeps playing. I only want it to play once, then pause for 3 seconds. How can I fix the code?
local debounce = false
script.Parent.Essentials.Giver.Touched:connect(function(hit)
if not debounce then
remoFun:FireClient(player) --play chaching money sound
debounce = true
end
wait(3)
debounce = false
you’ve must put this line below into if then statement:
wait(3)
debounce = false
so it will be:
local debounce = false
script.Parent.Essentials.Giver.Touched:connect(function(hit)
if not debounce then
remoFun:FireClient(player) --play chaching money sound
debounce = true
wait(3)
debounce = false
end
end)
I would also recommend putting debounce = truebeforeremoFun:FireClient(player) to ensure that it won’t run again while the remote function is being fired.