Can someone please help me figure out how to make this sword only do damage one time during the animation? The problem I'm having is "TakeDamage" is stacking the damage multiple times throughout the animation. I've tried adding in debounces. Perhaps all in the wrong places? Should I move the onTouch function inside the Attack function? Please help, I just want the weapon to animate and apply the damage once per swing. Thank you.
local sword = script.Parent
local canAttack = true
local canDamage = false
function onTouch(part)
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if canDamage == true then
character.Humanoid:TakeDamage(20)
end
end
end
sword.Blade.Touched:Connect(onTouch)
function Attack()
local attack = sword.Parent.Humanoid:LoadAnimation(script.SwordSwing)
if canAttack == true then
attack:Play()
canAttack = false
canDamage = true
wait(0.25)
canDamage = false
wait(0.5)
canAttack = true
end
end
sword.Activated:Connect(Attack)

3 comments
@GumzocklateE As is in the original script the player doesn't get damaged unless the sword is activated and the animation is in play. How would I reset the table after each swing?
@EpiXBloxorZ It should auto reset, since the table is set every time touched event is fired.
@GumzocklateE Okay I tested the script you provided. And the sword's TakeDamage is still stacking damaging the other humanoid for each tick or frame the sword is making contact with this player. I think the problem is the table is reset for each "touched" connect. So for the period of time the sword is making contact the table is "auto reseting" and the damage is still compounded.