For some reason why loop isn’t working even though it should. When a player activates I have a print and it prints correctly but the loop doesn’t work. I have no further explanation sorry.
Script:
local Debounce = 0
while Debounce ~= 0 do
wait(1)
Debounce -= 1
print("Subtracting")
end
--other stuff
Debounce = 10
Well the obvious answer is that it’s not running due to debounce being equal to 0. You made a loop that checks if it is NOT equal to zero (== is equal, ~= is not equal).
Setting the value later won’t matter as the script has already passed that thread. You’re probably thinking it may act like events such as .touched and such, since those activate regardless of position in the script.
The loop would only work once cause it’ll only detect when Debounce ~= 0 and that’s it, it won’t account for the other time when you set it back to 10
You could use a custom function to make this work, perhaps?
local Debounce = 0
local function DebounceCount()
while Debounce ~= 0 do
wait(1)
Debounce -= 1
print("Subtracting")
end
end
--other stuff
Debounce = 10
DebounceCount()