The first debounce works. Why is the second debounce not working? So the first debounce is so the NPC takes 25 damage every 0.5 second. The second debounce is suppose to wait 5 seconds before the player gets EXP because when the NPC is dead, and the part touched the NPC again while he is dead, it gives the player more EXP. Is there a way to give the player EXP once when he kills the NPC?
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)
The value of debounce2 is only made false again if the condition "hit.Parent.Humanoid.Health==0" return true, otherwise it never gets set so debounce2 is now forever true.
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
Consider adding another debounce2=false, possibly in an else statement OR by swapping lines 15 and 16 ("debounce2=false" and the end after it) so the wait is the only thing that delays it.
Happy to help :) CD.