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
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)