I made 2 different debounces but the second one is not working. Why is that?

local debounce = false
local debounce2 = false
local player = game.Players.LocalPlayer

function onTouched(hit)
	if not debounce then
		debounce = true
		if hit.Parent.Name:sub(1,17) == "AFK Noob Lv 1 HP " then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
			if not debounce2 then
				debounce2 = true
				if hit.Parent.Humanoid.Health == 0 then
					player.leaderstats.EXP.Value = player.leaderstats.EXP.Value + 16
					wait(5)
					debounce2 = false
				end	
			end
			wait(0.5)
			debounce = false
			elseif hit.Parent.Name:sub(1,4) == "Noob" then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
			wait(0.5)
			debounce = false
        end
    end
end

script.Parent.Touched:connect(onTouched)

5 comments

0

What is it supposed to do?

0

Swap lines 23 and 24.

0

I tried swapping lines 23 and 24, but it didn't work

0

Put line 15 after line 16.

0

Sorry it still doesn't work idk why