Error - Unable to cast value to Object

So I’ve rigged a viewmodel and I’m trying to load an animation that I made with that specific model.

Here is the code:

local char = script.Parent
local vmodel = workspace.CurrentCamera:FindFirstChild(char.Name.."_VMODEL")
local vhum = vmodel:WaitForChild("Humanoid")
local hum = char:WaitForChild("Humanoid")

local WalkAnimID = 9289981604


hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	
	if hum.MoveDirection.Magnitude ~= 0 then
		
		if hum.WalkSpeed == 16 then
			
			vhum:LoadAnimation(WalkAnimID):Play()
			
		end
		
	end
	
end)

And here is how the viewmodel looks inside the explorer:
image

(I have tried to use an animation object aswell)

If there is something I don’t know about animations then probably what you did wrong here is that you need to load a animation object instead of the ID

oh yeah btw you should use animator to load the animation instead of the humanoid because the humanoid loadanimation function is deprecated

local AnimationObject = script:WaitForChild("Animation")
local anim = animator:LoadAnimation(AnimationObject)

As you can see at the bottom of the post I have tried to use an animation object, when I try that I get an issue about something wrong about the asset id protocol. I know there isn’t any problem, I’ve checked multiple times on the website to see if the ID was wrong but it wasn’t.

Animations don’t work if it’s not uploaded by you so make sure it is made by you

Edit: reworded it cause it sounded confusing

The animation is uploaded by me. I think it has to be something about how I rigged the viewmodel as I’m new to rigging. That’s why I left a screenshot of the explorer

It might be the rigging then cause I went through some of my other VM and they all have a torso part
If you want help with making a first person VM then I’d recommend using this tutorial framework as it’s a good starting point

P.S this tutorial also helps you with the viewbobbing

This does not cover how to rig properly. This is a complete FPS framework and I don’t want that. I just want a simple viewmodel with a single weapon being equipped all the time and the feature to animate the viewmodel. This should be easy on paper, but the animation part doesn’t work unfortunately.

The issue is that you’re passing an integer. LoadAnimation requires an Animation Instance.

To fix the issue, create an Animation Instance and insert the animation id from the script into the AnimationId property and pass the object into the parameters

I tried that, when I try that I get an issue about something wrong about the asset id protocol. I know there isn’t any problem, I’ve checked multiple times on the website to see if the ID was wrong but it wasn’t.

Have you tried inserting rbxassetid://9289981604 into the property?

After a little experimenting it may be because the ID that was put inside the animation object was wrong

The ID in the object should look like this

rbxassetid://numbers

That works, never encountered that issue before, it used to do the rbxasset by itself. Hm weird. Thank you anyways

1 Like