hi, im fairly new at scripting, and trying to make a strategy game but when i spawn the npc it walks normally but when it attacks the walking animation is overlaying the attack animation. I do not know why this is happening
local animation = script.Parent.Animation
local animationtrack = script.Parent.Humanoid.Animator:LoadAnimation(animation)
animationtrack.Priority = Enum.AnimationPriority.Action
while task.wait() do
local target = FindTarget()
if target then
if (target.position - script.Parent.HumanoidRootPart.Position).Magnitude < attackRange then
local backswing = 0.5
script.Parent.Animate.Enabled = false
script.Parent.Humanoid:MoveTo((script.Parent.HumanoidRootPart.Position))
animationtrack:Play()
animationtrack.Stopped:Wait()
script.Parent.HumanoidRootPart.Anchored = false
script.Parent.Animate.Enabled = true
local target = FindTarget()
task.wait(backswing)
else
script.Parent.Humanoid:MoveTo(target.Position)
end
end
end
1 Like
You’re saying that the walking animation is overlaying the attack animation, right? That probably means that they are playing both at the same time and the animations are both “mixing” with each other.
I am guessing that you want the fight animation to play, while the walking animation is still playing, without the walking actually showing since you are unanchoring the humanoidrootpart after playing the attack animation so walking wouldnt make much sense while attacking.
So this is your attack animation:
local animation = script.Parent.Animation
local animationtrack = script.Parent.Humanoid.Animator:LoadAnimation(animation)
animationtrack.Priority = Enum.AnimationPriority.Action
Try changing this:
animationtrack.Priority = Enum.AnimationPriority.Action
to this:
animationtrack.Priority = Enum.AnimationPriority.Action2
Action2 will override the walking animation like how the walking animation overrides the idle animation. There’s also Action3 and Action4 but you don’t need that here. Only Action2 is necessary in your situation. It depends on how many animations you want to stack here.
But instead of doing this you can also just stop the walking animation I guess. Both of these solutions should work. But I would recommend changing “Action” to “Action2” first and seeing if it works.
it kinda worked, but how do i stop the walk animation as it is in another Animate script because now the rig’s legs are walking as the attack animation has no keyframes for the legs