Debounce system not working

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
1 Like

Does the t:Play() work? Or not?

Yes it works (character limit).

try writing a print("hi roblox") before wait(1) and a print("bye roblox") after wait(1) and tell me what you got in the output

It printed both but after it printed it wouldn’t work

hi (x3)
bye (x3)
(character limit)

Where’s the rest of your script?

Do you get any errors in the Output window?

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.

Instead of print("hi") or ("bye") try print(Combo.Value) so you can tell what each of the if statements are dealing with.

Why do that when you can do:

if debounce == false then

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.

1 Like