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
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
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
since my solution didn’t work, let’s try other things. Go trough them one by one:
Try my first solution again (with a few changes this time) by changing the priority of the walking animation to “Movement” and changing the priority of your attack animation back to “Action”. I tested it myself and it seems to work.
In your script above you are unanchoring the HumanoidRootPart after finishing the attack animation, meaning it must be anchored while doing the attack. You could try to implement a loop in your script (the script which controlls the walking animation) which always checks if the humanoidrootpart is anchored or not. If it is, then you can stop the walking animation.
An even better solution would be to use this:
script.Parent.HumanoidRootPart:GetPropertyChangedSignal("Anchored"):Connect(function() -- Gets activated when the "Anchored" property gets changed
if script.Parent.HumanoidRootPart.Anchored == true then
-- Here you stop your walking animation
-- if necessary, use "else" to make the animation play again after unanchoring
-- like this:
else
-- here you will play your animation again
end
end)
(It’s the same but without a loop. Also, I don’t know where your walking script is located so I am assuming it’s inside the rig)