Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i fix this error "Unable to cast value to Object" while loading an animation?

So I have enounctered this error which says "Unable to cast value to objest" while loading an animation, and it doesn't say anything else, didn't find anything useful about this. And no i don't need debounce, and IsTyping, just need a fix for this, if possible.

Code:

wait(2) local Character = game.Players.PineRox.Character local UIS = game:GetService("UserInputService")

local Animation = Instance.new("Animation") Animation = 'rbxassetid://4682522673'

UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.F then local LoadAnimation = Character.Humanoid:LoadAnimation(Animation) LoadAnimation:Play() end end)

1 answer

✓ Accepted answer
wait(2)
 local Character = game.Players.PineRox.Character
 local UIS = game:GetService("UserInputService")

local Animation = Instance.new("Animation") 
Animation.AnimationId = 'rbxassetid://4682522673' --here's the error you need to put .AnimationId not the object animation

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then 
		local LoadAnimation = Character.Humanoid:LoadAnimation(Animation) 
		LoadAnimation:Play() 
	end 
end)

1 comment

0

btw at line 1 you can change PineRox to LocalPlayer

This discussion is preserved as it was. New answers, comments, and votes are closed.