#Only Deal damage when swing animation

6 messages · Page 1 of 1 (latest)

daring oasis
#

Hello, I have a problem, I want my sword only to do damage when the animation plays. Thanks.
I
I
v

--UTILLITY__
local tool = script.Parent
local canhit = false
local debounce = false
--MODIFIERS--
local Damage = 17
local waittime = 15
local fling = 0
--ANIMATION--
local animloop = 1
local anim1 = script.Parent.anim1
local anim2 = script.Parent.anim2

script.Parent.Activated:Connect(function()
    if debounce == false then
        --animation loop
        local humanoid = tool.Parent.Humanoid
    
        if animloop == 1 then
            animloop = 2
            local animation = humanoid:LoadAnimation(anim2)
            animation:Play()
        else
            animloop = 1
            local animation = humanoid:LoadAnimation(anim1)
            animation:Play()
        end
        --Debounce
        canhit = true
        debounce = true
    
        wait(waittime)
    
        canhit = false
        debounce = false
    end
    
end)

tool.Handle.Touched:Connect(function(hit)
    if canhit == true then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        local rootpart = humanoid.Parent.HumanoidRootPart
        local BodyVelocity = Instance.new("BodyVelocity", rootpart)
        --Damage
        humanoid.Health = humanoid.Health - Damage
        --Fling Script
        BodyVelocity.Velocity = Vector3.new(math.random(0, fling), math.random(0, fling), math.random(0, fling))
        rootpart.Velocity = Vector3.new(math.random(0, fling), math.random(0, fling), math.random(0, fling))        
    end
end)
upper creek
daring oasis
upper creek
daring oasis
#

nvm