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

unable to cast value to object, why isn't my animation working?-

Asked by 5 years ago
01local player = game.Players.LocalPlayer
02local character = player.Character or player.CharacterAdded:Wait()
03local humanoid = character:WaitForChild("Humanoid")
04local animation = Instance.new("Animation",character)
05local animationId = "rbxassetid://4873199438"
06 
07if humanoid then
08    wait(3)
09local loadAnimation = character.Humanoid:LoadAnimation(animationId)
10loadAnimation:Play()
11end

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You need to cast the AnimationObject to the Humanoid, not the ID:

1local Animation = Instance.new("Animation")
2Animation.AnimationId = "rbxassetid://"..4873199438
3Animation.Parent = Character --// Secondary argument of Instance.new was deprecated
4 
5Character.Humanoid:LoadAnimation(Animation):Play()

If that helped, don’t forget to accept this answer!

0
thank you! Code1400 75 — 5y
Ad

Answer this question