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

What does it mean, "Unable to cast value to Object"?

I am trying to load an animation, and store it in a variable. I have looked at the roblox api, and based on what I see on that webpage, my code should work. My code is here:

game.ReplicatedStorage.RemoteEvents2.Spells.ignis.OnServerEvent:Connect(function(player)
	
	local loadedAnimation = player.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.MelAnim.INC.AnimationId)
	loadedAnimation:Play()
	print("PLAYING")
	
end)

As you can see, this should work (the directories are correct, but you will just have to take my word for that).

If there is something that I am missing, I would appreciate being told so. Otherwise, I am out of luck.

Happy scripting, and all help is welcomed.

Edit: Does the same thing if I combine the two lines:

game.ReplicatedStorage.RemoteEvents2.Spells.ignis.OnServerEvent:Connect(function(player)
	
	player.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.MelAnim.INC.AnimationId):Play()
	print("PLAYING")
	
end)

1 comment

1

I am working with junior scripters, so they are of little help.

1 answer

✓ Accepted answer

When you load an animation, you cannot use the ID. You need to use the animation object, basically ID is nearly pointless for playing sadly.

e.g:

game.ReplicatedStorage.RemoteEvents2.Spells.ignis.OnServerEvent:Connect(function(player)
    local anim = player.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.MelAnim.INC)
    player.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.MelAnim.INC):Play()
    print("PLAYING")

end)

pls do stuff if it helped idk what that stuff is

And to answer your actual question, you cannot cast the Play() function to something that doesn't support it, such as an animationID as opposed to an animation object.

1 comment

0

I can honestly not remember if this answer worked, or if it led me to a conclusion about something else in my script, but thank you.

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