NPC animation unable to play

Hello,

The modulescript below is a simple script that loads,plays, stops animations on npc models that i spawn on a wave basis. The way i load animations is that when a new npc spawns the script that spawned them loads the animation for the npc, and the way i play/stop it is on walkspeed changes.

The problem is that it loads the animation but it can’t play it.

local module = {}

function module.LoadAnimations(Character)
	local AnimationsFolder = Character:FindFirstChild("Animations")
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	
	Walk = AnimationsFolder:FindFirstChild("Walk")	
	Humanoid.Animator:LoadAnimation(Walk)
end

function module.PlayWalkAnimation()
	Walk:Play()
end

function module.StopWalkAnimation()
	Walk:Stop()
end

return module

This is the section of the serverscript that does the description i explained above

local ClonedZombie = ZombieFolder[Name]:Clone()
			ClonedZombie.PrimaryPart.CFrame = Location + Vector3.new(0,3,0)

			for i, Obj in ipairs(ClonedZombie:GetDescendants()) do
				if Obj:IsA("BasePart") then
					Physics:SetPartCollisionGroup(Obj,"Mobs")
				end
			end

			ClonedZombie.Parent = game.Workspace.Mobs
			ClonedZombie.PrimaryPart:SetNetworkOwner(nil)
			
			AnimationHandler.LoadAnimations(ClonedZombie)
			
			local Humanoid = ClonedZombie:FindFirstChildOfClass("Humanoid")
			
			Humanoid.Died:Connect(function()
				task.wait(0.3)
				ClonedZombie:Destroy()
			end)
			
			Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
				if Humanoid.WalkSpeed > 0 then
					AnimationHandler.PlayWalkAnimation()
				else
					AnimationHandler.StopWalkAnimation()
				end
			end)
1 Like

You didn’t load the animation so make sure to load it