The title says it all. It's probably a really stupid question with an obvious answer.
There are two ways you can do this.
01 | function foo() |
02 | if debounce then return end --If debounce is true, stop the function without doing anything |
03 | local debounce = true |
04 |
05 | print ( "Hello, world" ) |
06 | --Do some stuff Here |
07 |
08 | wait( 1 ) --Wait 1 second |
09 |
10 | debounce = false --Make the function callable again |
11 | end |
12 |
13 | foo() --Prints "Hello, world" |
14 | 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:
01 | local lastCalled = 0 |
02 | function foo() |
03 | if tick() - lastCalled < 1 then return end --Do nothing if 1 second has not passed |
04 | lastCalled = tick() |
05 |
06 | print ( "Hello, world" ) |
07 | --Do stuff here |
08 | end |
09 |
10 | foo() -- Prints "Hello, world" |
11 | 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
1 | wait() |
The amount of time would go into the to parenthesis. :)