LoadAnimation does not work and yields the script with no error or warning

This is script

local collector = game:GetService("CollectionService")

workspace.DescendantAdded:Connect(function(des)
	if collector:HasTag(des,"AI") then
		
		print("NewZombie")
		
		local NewThread = coroutine.create(function()
			
			local Anim = des.Zombie:LoadAnimation(script.Animation)
			
			print("2")

			while wait(1) do

				print("Cycle")
				if des.Zombie.MoveDirection.Magnitude > 0 then
					print("run")
					local SpeedFactor = des.Zombie.WalkSpeed / 16

					Anim:AdjustSpeed(SpeedFactor)

					if Anim.IsPlaying ~= true then
						Anim:Play()
					end
				else
					print("stop")
					if Anim.IsPlaying ~= false then
						Anim:Stop()
					end
				end
			end
		end)
		
		coroutine.resume(NewThread)
	end
end)

When I remove the LoadAnimation and all the rest about it, the script works fine and it prints 2.
When I put the LoadAnimation back, it only prints NewZombie and no 2.

Before we try to solve the entirety of this, what is “des.Zombie”. Is it the Humanoid?

I suggest you try loading it into the Animator instead of a Humanoid, assuming “Zombie” is the Humanoid, as there was been a recent change which deprecated this and it’s better to use the new method. (change: Deprecating LoadAnimation on Humanoid and AnimationController)

2 Likes

I’ve been using the same exact method for making animations for a set of zombies, the MoveDirection was not working so I ended up in taking a default animation script and changing the IDs before activating it.

Yes, it is. It is a humanoid named Zombie