Many people, including myself, have run into this error. I haven’t found any working solutions on the DevForum, and I spent days trying to figure out how to fix this. Today I ended up figuring it out, and I decided to post it here.
Code that would error like this:
local players = game:GetService('Players')
local animationId = 13571756345
local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://'.. animationId
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild('Humanoid')
local animator = humanoid:WaitForChild('Animator')
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
end)
end)
Simple fix:
Add
game:GetService('RunService').Stepped:Wait()
before you load the animation.
Example:
local players = game:GetService('Players')
local animationId = 13571756345
local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://'.. animationId
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild('Humanoid')
local animator = humanoid:WaitForChild('Animator')
game:GetService('RunService').Stepped:Wait()
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
end)
end)
Secondly, I have seen this alternative method recently. If the above method doesn’t work for you, try this tutorial: https://www.youtube.com/watch?v=iW6A1DkRY7w
I hope this helps!