I made a simple debounce system for combat, and when it gets to the part when It says wait(1) it gets stuck there and doesn’t do anything when I click again. Please help.
Script:
local debounce = false
if Combo.Value == 0 then
if debounce ~= true then
debounce = true
t:Play()
wait(1)
debounce = false
v.Humanoid:TakeDamage(dmg.Value)
Combo.Value += 1
elseif Combo.Value > 0 and Combo.Value < 5 then
if debounce ~= true then
debounce = true
t:Play()
wait(1)
debounce = false
v.Humanoid:TakeDamage(dmg.Value + StarterHit)
Combo.Value += 1
elseif Combo.Value == 5 then
if debounce ~= true then
debounce = true
t:Play()
wait(1)
debounce = false
v.Humanoid:TakeDamage(dmg.Value + StarterHit)
Combo.Value -= Combo.Value
You said when it gets to the wait(1) it gets stuck. There are 3 wait(1)s in the section of script you posted.
You should put the debounce at the end of those sections because if the script is running and checking for Combo.Value and it gets called again then there’s a millisecond chance that the debounce will not work and you’ll get the TakeDamage repeated.
Try this:
local debounce = false
-- call this section with your function, or while true do, or however
if debounce ~= true then
debounce = true
t:Play()
if Combo.Value == 0 then
v.Humanoid:TakeDamage(dmg.Value)
Combo.Value += 1
elseif Combo.Value > 0 and Combo.Value < 5 then
v.Humanoid:TakeDamage(dmg.Value + StarterHit)
Combo.Value += 1
elseif Combo.Value == 5 then
v.Humanoid:TakeDamage(dmg.Value + StarterHit)
Combo.Value -= Combo.Value
end
wait(1)
debounce = false
end
-- end of function or end of while true do loop or however you are calling this code.
What’s the purpose of checking the debounce so frequently? It should be checked once at the start of the function then enabled then disabled at the end of the script.