I tried adding a debounce to the giving EXP because when the NPC is dead, and you click, it still gives you EXP. My debounce is not working. Is there a better way to give EXP when the killer kills the NPC? I want it to give EXP once. Thanks!
local debounce = 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 hit.Parent.Humanoid.Health == 0 then player.leaderstats.EXP.Value = player.leaderstats.EXP.Value + 16 wait(5) -- I want it to wait 5 seconds before it gives EXP debounce = false -- I tried this, but it doesn't work xD 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)
I also tried this:
local debounce = 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 if not debounce then debounce = true hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25 if hit.Parent.Humanoid.Health == 0 then player.leaderstats.EXP.Value = player.leaderstats.EXP.Value + 16 wait(5) debounce = false 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 end script.Parent.Touched:connect(onTouched)