Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

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

Asked by
appxritixn 2235 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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
I am working with junior scripters, so they are of little help. appxritixn 2235 — 4y

1 answer

Log in to vote
1
Answered by
Gojinhan 353 Moderation Voter
4 years ago
Edited 4 years ago

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.

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. appxritixn 2235 — 4y
Ad

Answer this question