local hum = script.Parent:WaitForChild(“Humanoid”)
local anim = hum:LoadAnimation(script.Parent.Eat)
while anim.Length <= 0 do task.wait() end
anim:Play()
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)
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)
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.
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.