Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Animation doesn't damage on touch ? It damages even if the animation is not used...

Asked by 7 years ago
Edited 7 years ago
player = game.Players.LocalPlayer

animation = script:WaitForChild("Animation")
animation2 = script:WaitForChild("Animation2")

enabled = true

ra = player.Character:WaitForChild("RightLowerArm")

dmg = script.Damage.Value -- Damage Value

game:GetService("UserInputService").InputBegan:connect(function(input,proc)
    if  input.KeyCode == Enum.KeyCode.Q then
        if enabled then
            enabled = false

            local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
            animationTrack:Play()
            wait(0.9)
local animation2Track = player.Character.Humanoid:LoadAnimation(animation2)
animation2Track:Play()
wait(1)
            enabled = true
        end
    end
end)

function onTouch(ra)
    local humanoid = ra.Parent:FindFirstChild("Humanoid") -- Finding Humanoid of The Enemy
    if humanoid ~= nil and enabled == true then
        humanoid.Health = humanoid.Health - dmg -- Where the damage won't work.
    end
end
ra.Touched:connect(onTouch)

1 answer

Log in to vote
0
Answered by
Vrakos 109
7 years ago
Edited 7 years ago

The reason it's working when the animation is not being used is because the touched function checks if enabled is true. You've set it to true by default, and when the animation is in progress, in theory, disable the touched event.

This should work:

player = game.Players.LocalPlayer

animation = script:WaitForChild("Animation")
animation2 = script:WaitForChild("Animation2")

enabled = false

ra = player.Character:WaitForChild("RightLowerArm")

dmg = script.Damage.Value -- Damage Value

game:GetService("UserInputService").InputBegan:connect(function(input,proc)
    if  input.KeyCode == Enum.KeyCode.Q then
        if not enabled then
            enabled = true

            local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
            animationTrack:Play()
            wait(0.9)
local animation2Track = player.Character.Humanoid:LoadAnimation(animation2)
animation2Track:Play()
wait(1)
            enabled = false
        end
    end
end)

function onTouch(ra)
    local humanoid = ra.Parent:FindFirstChild("Humanoid") -- Finding Humanoid of The Enemy
    if humanoid ~= nil and enabled == true then
        humanoid.Health = humanoid.Health - dmg -- Where the damage won't work.
    end
end
ra.Touched:connect(onTouch)

Ad

Answer this question