:LoadAnimation() "Unable to cast value to object"

Hey,

Recently I made a Pose GUI for my profile maker game, and I just got this error?
image

The code:

wait()
anim = "rbxassetid://NoIdForYou"
script.Parent.MouseButton1Down:Connect(function()
     game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim)
end)

Why is this happening? I’ve tried to fix it many times now…

Learned that it only works with instances

1 Like

Side note, but do consider looking at the Humanoid’s Animator object, it’s more modern :wink:

wait()
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local anim = AnimationInstance

script.Parent.MouseButton1Down:Connect(function()
     local Animator = Humanoid:WaitForChild("Animator")
     local LoadAnim = Animator:LoadAnimation(anim)

    LoadAnim:Play()
end)
2 Likes

Loading the animation on the Humanoid is deprecated.

Consider using,

local Animator = Humanoid:WaitForChild("Animator")

Animator:LoadAnimation(anim)

instead! :wink:

@Jackscarlett already posted this, but thanks for the info

I saw your post don’t hide it aha

I’m frequently on here! Just attempting to help others whilst at the same time being chill & doing it with a humorous twist! Also for future reference, here’s a general term on what “deprecated” is from an analogy if you’re not certain on what it is: