NPC animation not working

i have a simple npc animation script, but this script no longer works. do you have any ideas of how to fix it?

there is no animation played…

local Humanoid = script.Parent:FindFirstChild("Humanoid")
local Animation = script:WaitForChild("Animation")


local LoadedAnim = Humanoid:LoadAnimation(Animation)


LoadedAnim:Play()


Humanoid:LoadAnimation() is now deprecated. There’s something called Animator under a character’s humanoid. So instead, use Animator:LoadAnimation().

3 Likes

do you mean animation controller?

No, that’s also deprecated as well. So, you can use WaitForChild(“Animator”) on the humanoid, then use LoadAnimation(animationInstance) and then play it.

oof lots of deprecation with animations…

so like this?

local animator = humanoid:WaitForChild("Animator")
local animation = animator:LoadAnimation(animation)
animation:Play()

Warning! You’re using the variable named animation as the animation instance inside LoadAnimation()! Either change your variable name or your animation instance name to something else.

ok. I changed the variable to loadedanim, how would I loop the animation? either it’s that I’m not loading in fast enough to see the animation or it’s not working…

If you want the animation to loop, when your creating the animation, click the looping button, or alternatively you could use AnimationTrack.Stopped to see when the animation is done playing and then play the animation again

image
[not in screenshot but there’s an animation inside the script with a working animation id]
here’s my script, it still doesn’t work. do you know what the issue could be?

local humanoid = script.Parent:FindFirstChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")
local Animation = script:WaitForChild("Animation")


local LoadedAnim = animator:LoadAnimation(Animation)
LoadedAnim:Play()

LoadedAnim.Stopped:Connect(function()
	LoadedAnim:Play()
end)




I would suggest go to Plugins>AnimationEditor>then press the looping button

1 Like

Then whenever you want to stop it while its looping AnimationTrack:Stop()