Animation Script Issue

Hey everyone! :wave:

I’m currently trying to make a model dummy in my game play an animation endlessly, although this script isn’t working with no errors. Does anyone know how to fix it? If so, please let me know!

Script:

local animation = Instance.new("Animator")

animation.Parent = script.Parent.Humanoid

animation:LoadAnimation(script.Animation):Play()

Thank you in advance for your assistance with this, much appreciated! :heart:

Hi there!

You can try this script, it should work.

local Animation = Instance.new("Animation")
Animation.Parent = script.Parent.Humanoid

local AnimationId = 0 -- Your AnimationId here
Animation.AnimationId = "rbxassetid://"..AnimationId

script.Parent.Humanoid:LoadAnimation(script.Parent.Humanoid.Animation):Play()

You can view the API Reference for animations here:

1 Like

I believe :LoadAnimation is deprecated and you need to use an Animator to make it work?

LoadAnimation is not deprecated and I believe animator is for models that don’t have a humanoid

Okay, I’ll try this, thank you! (30 ch.rsssssss)

It’s still not working, if it’s working but only playing it once then I’m not noticing it because I’m loading in to the game. Maybe it’s because it’s not looping it? How would I loop it?

is the game published to you or your group? if it is published to your account… make sure that the animation is also published in your account

1 Like

Hi there, if you want to loop your animation, you can use the Looped property of animation track:

local Animation = Instance.new("Animation")
Animation.Parent = script.Parent.Humanoid

local AnimationId = 0 -- Your AnimationId here
Animation.AnimationId = "rbxassetid://"..AnimationId

local AnimationTrack = script.Parent.Humanoid:LoadAnimation(Animation)

AnimationTrack.Looped = true

AnimationTrack:Play()

It’s still not working. I don’t know what the issue is.

You have it the other way

Yes, LoadAnimation is deprecated, but only inside the Humanoid/AnimationController properties

Using it on an Animator object will work fine

local Animator = Instance.new("Animator")
Animator.Parent = script.Parent.Humanoid

print("Created Animator")
print(Animator.Parent)

local PlayAnim = Animator:LoadAnimation(script.Animation)
PlayAnim:Play()
print("Playing animation")

Make sure the Animation that you’re playing is owned by you, and the script.Animation is an Animation object of some sort

Wasn’t sure if Animators only work for players or not, guess we’ll find out soon enough if you try the script

1 Like

You deleted it…? (30 ch.rssssss)

did you tested your animation with existing Animator ?

1 Like

This isn’t working. :frowning: (30 ch.rssssss)

okay i got it, you should try to change animation priority

Did you get any print statements at all?

I’ve tried that. (charssssssssssssss)

Ah my apologies, hadn’t seen the deprecation of load animation on humanoids.

can you prepare a gif about your problem ?

Printed everything and it looks like it’s working fine in the Output, but it’s not actually playing the animation for some odd reason.

image

Edit: It might be playing once but I’m not seeing it because I’m still loading in, how do I loop it?

AnimationTrack.Looped = true should make the animation looped. If not, try republishing the animation with looped toggled from the animation editor.