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

Simple debounce doesn't seem to work?

So I have a debounce in my touched function to stop the API from being overloaded. The code is as follows;

TestPart.Touched:Connect(function(Part)
	local debounce = true
	if debounce then
		debounce = false
	wait(5)
	debounce = true
	end
end)

I'm not sure why this is happening because it's a pretty simple/basic concept When the code is ran, the debounce doesn't do anything, and the code isn't ran every 5 seconds if the player touches it.

2 comments

0

Try moving the debounce variable outside of the function

0

I did but now the code doesn't run at all even if debounce is true

1 answer

Hi, what this looks like to me is that you aren't "checking" to see the value. All you have to add is ==! :)

local debounce = true

TestPart.Touched:Connect(function(Part)
	if debounce == true then
		debounce = false
		wait(5)
		debounce = true
	end
end)

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