deleted this old post because of age
if debounce == true then
wait(2)
print("Debounce is set to false")
debounce = false
Are these lines necessary? It looks like when you touched the object multiple times, they pass the debounce statement, wait two seconds, then set the debounce to false. And it looks like you’ve touched it 8 times since the debounce was set to true. Try removing these lines and testing your code; the rest of it looks fine.
Also, make sure you set debounce = false
outside of the if humanoid ~= nil
statement.
Another thing I’d like to note is that touched is an event; it will fire whenever something is touched, and it won’t wait for the previous call. This is why the debounce is necessary. Checking if the debounce is true, in this case, would be redundant*.
So alright here’s what happens:
Step-1 check if Debounce == true, if it isn’t true Elseif runs
Elseif-Step-2 check if Debounce == false, then Debounce == True in the if-statement.
Print(“Touched”) fires 9 times
Print(“Debounce is set to false”) fires 8 times
The first Touched makes the Debounce set to True because of this behavior Print(“Debounce is set to false”) will only fire 8 times and not 9 times.
PS: I don’t have a computer right now but I hope this helps!
EDIT remember to reset global variables if they are going to be used more than once
Remove this part:
if debounce == true then
wait(2)
print("Debounce is set to false")
debounce = false
Then change elseif
to if
.
since debounce is false its gonna run the if debounce== false line, its gonna make the debounce true and then its gonna run the if debounce == true line