How do you add debounce in this script? I want it to wait 4 seconds before it does the second part of the coding when touched. So, it does the first action, then wait 4 seconds, next do the second action, and at last wait another 4 seconds before it does the first action again. Thanks!
local boolean = false
function onTouched()
if boolean then
boolean = false
--code
wait(4)
else
boolean = true
--code
wait(4)
end
end
script.Parent.Touched:connect(onTouched)

7 comments
Sorry but I need it to do the second action, I think this only does 1 action
What do you mean?
Is that what you mean?
Sorry that I am not clear xD I mean like when it is touched the first time, it does something. Then when it is touched the second time, it does a different action.
Okay, I think I got it this time
Thanks it worked! I have two questions, but it is not necessary to answer them, you can just ignore them if you want. Is boolean still nessesary ? Also, is there an official word to replace "action"?
Boolean is the debounce, you can rename it to whatever you like, as for your second question, I don't know. Maybe scope? I'm still new to scripting myself.