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)
✓ ANSWER ACCEPTED
My Animation doesn't damage on touch ? It damages even if the animation is not used...
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
