Pathfinding NPC Animation

I am attempting to give an NPC a walking animation, that activates when he walks to a destination, to another. No matter what animation I load and play, it does not work and the NPC moves without walking, what is wrong within the script?

local PatrolPoints = game.Workspace["Patrol Route"]
local humanoid = script.Parent:WaitForChild("Humanoid")
local attack = false
local anim = script.Parent.Animation
local animTrack = humanoid:LoadAnimation(anim)



while attack == false do
	for patrol = 1, #PatrolPoints:GetChildren() do
		animTrack:Play()
		humanoid:MoveTo(PatrolPoints[patrol].Position)
		humanoid.MoveToFinished:Wait()
		animTrack:Stop()
		wait(5)
	end
end

try using an animator. You are loading the animation to the humanoid

Your animations keeps starting whenever it is walking. Try this.

while true do
	if attack == false then
		for patrol = 1, #PatrolPoints:GetChildren() do
			if animTrack.IsPlaying == false then
				animTrack:Play()
			end

			humanoid:MoveTo(PatrolPoints[patrol].Position)
			humanoid.MoveToFinished:Wait()
			animTrack:Stop()
			wait(5)
		end
	else
		animTrack:Stop()
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.