The title says it all. It's probably a really stupid question with an obvious answer.
There are two ways you can do this.
function foo() if debounce then return end --If debounce is true, stop the function without doing anything local debounce = true print("Hello, world") --Do some stuff Here wait(1) --Wait 1 second debounce = false --Make the function callable again end foo() --Prints "Hello, world" foo() -- Does nothing because 1 second has not yet elapsed
The second way is to store the time the function was last called, and return if not enough time has elapsed yet:
local lastCalled = 0 function foo() if tick() - lastCalled < 1 then return end --Do nothing if 1 second has not passed lastCalled = tick() print("Hello, world") --Do stuff here end foo() -- Prints "Hello, world" foo() -- Again, does nothing because 1 second has not yet elapsed
It depends how long to you want it to wait if you want it to wait a certain amount of seconds just say
wait()
The amount of time would go into the to parenthesis. :)