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

How do I play a tool animation?

Asked by 3 years ago

Hello,

I'm trying to play an animation I created and exported from this guide when a tool is activated, however for some reason the animation does not play.

My script (a child of the tool)

local tool = script.Parent
local Players = game:GetService("Players")

tool.Activated:Connect(function()
    print("Activated")
    local humanoid = tool.Parent.Humanoid

    local animation = Instance.new("Animation")
    animation.Name = "Animation"
    animation.AnimationId = "rbxassetid://7195581723"

    local animationTrack = humanoid:LoadAnimation(animation)
    animationTrack.Looped = false
    animationTrack.Priority = Enum.AnimationPriority.Action
    animationTrack:Play()

    print("Playing animation.")

    wait(animationTrack.Length)

    print("Animation finished, destroying instance.")
    animationTrack:Destroy()
    animation:Destroy()
end)

The messages show in the game output, but the hand holding the tool does not move.

Am I doing something wrong?

Answer this question