Play running animation when NPC is running

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to code a run animation that works with the walking animation for my NPC. Basically, if they see the player I want them to run up to them and play the running animation instead of the normal walking animation.

  2. What is the issue? Include screenshots / videos if possible!
    Whenever I try to I run into only the walking animation playing.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using bool values to set running, but the movement script ignores the bool value completely. And since that doesn’t work it is no longer included in the animation script. I have looked everywhere but have not found anything.

Here is my code, how would I incorporate it to have a running animation play and stop the walking animation whenever I want it to?

local NPC  = script.Parent

local Animator = NPC.Humanoid:WaitForChild("Animator")

local Humanoid = NPC:WaitForChild("Humanoid")

local WalkAnim = Animator:LoadAnimation(script:WaitForChild("WalkAnim"))

Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		WalkAnim:Play()
	else
		WalkAnim:Stop()
	end
end)
2 Likes

Where is the run animation? This script contains no reference to it.

The run animation’s parent is the script, I tried scripting a run animation but it just doesn’t work so I removed it from the script.

maybe this. what you mean is. I don’t fully understand this but I can only help with that

local NPC = script.Parent.Tes
local RunsAim = NPC.Run
local IdleAim = NPC.idle
local RunsAims = NPC.Humanoid:LoadAnimation(RunsAim)
local idleAims = NPC.Humanoid:LoadAnimation(IdleAim)

while true do 
	wait(0.5)	
	NPC.Humanoid:MoveTo(script.Parent.W1.Position)
	NPC.Humanoid.MoveToFinished:wait()
	RunsAims:Stop()
	idleAims:Play()
	wait(0.5)
	wait(5)
	NPC.Humanoid:MoveTo(script.Parent.W2.Position)
	NPC.Humanoid.MoveToFinished:wait()
	RunsAims:Play()
	idleAims:Stop()
	wait(5)
	NPC.Humanoid:MoveTo(script.Parent.W3.Position)
	NPC.Humanoid.MoveToFinished:wait()
	RunsAims:Stop()
	idleAims:Play()
	wait(5)
	NPC.Humanoid:MoveTo(script.Parent.W4.Position)
	NPC.Humanoid.MoveToFinished:wait()
	RunsAims:Play()
	idleAims:Stop()
	wait(5)
end

Thank you so much! I used bits from the code you gave me and it actually worked!