Animation Script Not Working

I have an animation script that gets the mobs in a folder, searches for the animation, animator, etc, then applies the animation. The problem is, it isn’t working. None of the warn messages are being fired, and no errors are appearing in the output, but the animations simply aren’t playing. I have tried looking on the Dev Forum, but nothing I have found works. Here is the script that I use to control my animations (located in StarterPlayerScripts):

local function animateMob(object)
	local humanoid = object:WaitForChild("Humanoid")
	local animationsFolder = object:WaitForChild("Animations")
	
	if humanoid and animationsFolder then
		local walkAnimation = object:WaitForChild("Walk")
		
		if walkAnimation then
			local animator = humanoid:FindFirstChild("Animator")
			
			if animator then
				local walkTrack = animator:LoadAnimation(walkAnimation)
				walkTrack:Play()
			else
				warn("Animator not found")
			end
		else
			warn("Walk animation not found")
		end
	else
		warn("Humanoid or Animations Folder not found")
	end
end
1 Like

Can you put a print() above this line and run it? This way, you know if it’s a problem with your animator or the order of execution.

1 Like

The print statement didn’t print.

I also just realized that no matter where I place the print statement within the function, it doesn’t print.

I think maybe it’s because it’s still waiting for the animations folder. or humanoid… did you try printing above those lines?

I just figured out the problem on accident. I forgot to add the :Connect(animateMob) to the bottom of the script. I also messed up where it got the walk animation, and instead of getting it from the animationFolder, I got it from the object. Here is the fixed script:

local function animateMob(object)
	local humanoid = object:WaitForChild("Humanoid")
	local animationsFolder = object:WaitForChild("Animations")
	
	if humanoid and animationsFolder then
		print("Humanoid")
		local walkAnimation = animationsFolder:WaitForChild("Walk")
		
		if walkAnimation then
			local animator = humanoid:FindFirstChild("Animator")
			
			if animator then
				local walkTrack = animator:LoadAnimation(walkAnimation)
				walkTrack:Play()
			else
				warn("Animator not found")
			end
		else
			warn("Walk animation not found")
		end
	else
		warn("Humanoid or Animations Folder not found")
	end
end

workspace.Mobs.ChildAdded:Connect(animateMob)
1 Like

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