i have this code but it executes alot without a cooldown?
01 | db = true |
02 |
03 | if not db = = false then |
04 |
05 | script.Parent.Parent.Name = "hi" |
06 | wait ( 2 ) |
07 | script.Parent.Parent.Name = "bye" |
08 |
09 | print ( "executed" ) |
10 |
11 | end |
12 | db = true |
I can only guess the reason in which you wanted to use a debounce was because you had a 'Touched' event previously, so to help me to understand I also added a touch event which you may change later if you wish.
Code:
01 | local debounce = false |
02 |
03 | script.Parent.Touched:Connect( function () |
04 | if not debounce then |
05 | debounce = true |
06 | script.Parent.Parent.Name = "Hi" |
07 | wait( 2 ) |
08 | script.Parent.Parent.Name = "Bye" |
09 | print ( "Executed" ) |
10 | debounce = false |
11 | end |
12 | end ) |
You just slightly had your debounces mixed up, but that seems to have solved the problem. Please accept my answer if it works, thanks.