SETTING THE STAGE: An NPC with a sword that slashes and when it hits a hit box damage gets taken away, only that the touched event fires 3 times every debounce turn
-
What do you want to achieve? Keep it simple and clear!
I want the touched event to work properly -
What is the issue? Include screenshots / videos if possible!
I’ve tested the debounce and it works perfectly fine, but in the touched event I put a if statement for a specific part that that fires like 3 times every next debounce turn that only fires once. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
All the solutions I found said add a debounce which I already had
T
snippet:
function swing()
if sword_debounce == false then
sword_debounce = true
local animation = humanoid:LoadAnimation(script.Animation)
local damage = true
animation:Play()
animation.Stopped:connect(function()
damage = false
wait(0.5)
sword_debounce = false
end)
local damged_humanoids = {}
NPC.Sword.Part.Touched:Connect(function(hit)
if hit.Name == "HitBox" then
print(hit)
end
if hit.Name == "HitBox" then
script.Parent.Sword.Blade.SwordSlash:Play()
local thing = hit.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
if thing then
thing:TakeDamage(5)
end
end
if hit.Parent:FindFirstChild("RedHealthg2") and _G.healthGreen > 0 and damged_humanoids[hit.Parent.Name] == nil then
script.Parent.Sword.Blade.SwordSlash:Play()
_G.healthGreen -= 0.2
damged_humanoids[hit.Parent.Name] = true
end
if hit.Parent:FindFirstChild("RedHealthb2") and _G.healthBlue > 0 and damged_humanoids[hit.Parent.Name] == nil then
script.Parent.Sword.Blade.SwordSlash:Play()
_G.healthBlue -= 0.5
damged_humanoids[hit.Parent.Name] = true
end
if hit.Parent:FindFirstChild("RedHealthBL2") and _G.healthBlack > 0 and damged_humanoids[hit.Parent.Name] == nil then
script.Parent.Sword.Blade.SwordSlash:Play()
_G.healthBlack -= 0.2
damged_humanoids[hit.Parent.Name] = true
end
end)
end
end