Why won't my Animation play?

My animation would not play. I think it has something to do with the bigger humanoid.

My script:

local hum = script.Parent:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script.Parent.Eat)
anim:Play()

The Model:

Screen Shot 2021-11-09 at 12.25.41 PM

The Animation:
https://www.roblox.com/library/7950314588/Eat-Titan

The Model:
Screen Shot 2021-11-09 at 12.26.55 PM

local hum = script.Parent:WaitForChild(“Humanoid”)
local anim = hum:LoadAnimation(script.Parent.Eat)
while anim.Length <= 0 do task.wait() end
anim:Play()

Try this

2 Likes

Thank you for the quick solution!

Np, to explain why this works its because when you load an animation it doesn’t return a fully loaded animation so you often have to wait until it loads (try not to have an animation with 0 length doe)

1 Like
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animation")
local animation = animator:LoadAnimation(script.Parent:WaitForChild("Eat"))
repeat
	task.wait()
until animation
animation:Play()

This is more accurate and doesn’t rely on the length of the animation. Also it’s recommended to use the “Animator” instance to load animations from now on.

That method won’t work since the animation track will exist, its just that the track itself is not loaded
(If the track didn’t exist then the length method wouldn’t of worked anyway cause then you would get an error like Attempt to index nil with length)

But yes use animator method to load animations

:WaitForChild("Eat") should allow for the “Animation” instance to load before attempting to create an “AnimationTrack” instance out of it.

Also is “animation” initialised before the “AnimationTrack” object is returned? Also is this being performed on the server or client?

The animation object itself will be loaded, but using LoadAnimation() will create a new object known as “AnimationTrack” which is different from the animation object, the AnimationTrack requires to be loaded aswell but since LoadAnimation() isn’t a yielding function The yield needs to be manual to gunaturee loading; Typically coders don’t play animations directly after loading, but rather preload the animations and play animations at some time later

If the animation object itself does not load, then you’ll get a different error similar to Sounds and Decals

This issue occurs on both client and server, Though I believe have higher chance to fail on server

I added a yield which I’m fairly positive will work, the variable “animation” shouldn’t be initialised until the entire “AnimationTrack” instance is returned and assigned to it.

Yes although there no gunaturee that it will take a heartbeat cycle to finish loading the animation, sometimes it can be longer

Since your using a repeat loop, its going to yield regardless of the state of the animation (since repeat loops function equal to do-while loops), and since the animation track exist the repeat loop only runs 1 cycle

“the variable “animation” shouldn’t be initialised until the entire “AnimationTrack” instance is returned and assigned to it.”

This is a false assumption, the animationtrack will return regardless if it has fully loaded or not

I’ve never heard of an object being returned in parts. I’d understand attempting to run an “AnimationTrack” instance before it has loaded and been assigned to the variable of which is being referenced to play the animation wouldn’t work.

I have tested your script, it doesn’t work. No errors in the output.

1 Like
local humanoid = script.Parent:WaitForChild("Humanoid")
local animation = humanoid:LoadAnimation(script.Parent:WaitForChild("Eat"))
repeat
	task.wait()
until animation
animation:Play()

If the “Animator” instance hasn’t been created for a prior “Animation” instance then you’d need to load the animation using the “Humanoid” instance instead.

Do not load the animation on humanoid, You can simply create a animator if it doesn’t exist Would not recommand this method 100%

I don’t know if you realized this or not, I have found a solution already, thank you for all your efforts tho!

Yeah I forgot to replace humanoid with animator, That code will work if replaced with animator

To avoid flooding you can message me on Thedagz#4176 on Discord if you want to debate about this more