I was making a touched function but I want to add a denounce so if they touch it in the matter of lets say 5 seconds then it wont fire but anything above 5 will. Ex: local de = false script.Parent.Touched:Connect(function() if de = false then de = true print (“hi”) wait(5) de = false end end). I’ve tried stuff like this but it just doesn’t work. Please help me
Can you format your code so we can see clear?
Well its not the code itself really its just like how should I use debounces and when… If you know what I mean. I just don’t understand how I’m supposed to implant them and how they are supposed to work.
local de = false
script.Parent.Touched:Connect(function()
if de = false then
de = true
wait(5)
de = false
end
end)
Apparently you are not using a comparison operator in the if statement, which explains why it is not working. Instead try if not de then
or if de == false then
. The code above is not a solution.
1 Like
It’s ==, not =. That’s how denounces work.
Ahh I see so something like
local buttonPressed = false
–Store whether the button is pressed in a local variable
Workspace.Button.Touched:Connect(function(hit)
if not buttonPressed then
– Is it not pressed?
buttonPressed = true
-- Mark it as pressed, so that other handlers don't execute
print("Button pressed")
wait(1)
print("Hi :D")
-- Do Stuff
buttonPressed = false
-- Mark it as not pressed, so other handlers can execute again
end
end)
1 Like