Animation not playing

Hello. I am making an animation that plays when the tool is activated but the animation doesn’t work? It gives me no errors it just doesn’t play

local Pickaxe = script.Parent
local Handle = game.StarterPack.StonePickaxe.Handle
local Animation = Pickaxe.Animation

Pickaxe.Activated:Connect(function()
	local Character = Pickaxe.Parent
	local Humanoid = Character.Humanoid
	
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	print("Pickaxe was activated")
	AnimationTrack:Play()
	print("Animation was played")
end)

Did you loop the animation and/or change its priority before you saved it?

1 Like

Use the Animator found inside of the Humanoid to load the animations as seen below:

local Pickaxe = script.Parent
local Handle = game.StarterPack.StonePickaxe.Handle
local Animation = Pickaxe.Animation

Pickaxe.Activated:Connect(function()
	local Character = Pickaxe.Parent
	local Humanoid = Character.Humanoid
	
	local AnimationTrack = Humanoid:WaitForChild("Animator"):LoadAnimation(Animation)
	print("Pickaxe was activated")
	AnimationTrack:Play()
	print("Animation was played")
end)
1 Like

Do what @OwlCodes said.

For a secure way of using the animator, do this:

local Pickaxe = script.Parent
local Handle = game.StarterPack.StonePickaxe.Handle
local Animation = Pickaxe.Animation



local function CheckAnimator(humanoid : Instance)
   if humanoid:FindFirstChildOfClass("Animator") then
       return humanoid.Animator
    else
        local Animator = Instance.new("Animator")
        Animator.Parent = humanoid
        return Animator
    end
end

Pickaxe.Activated:Connect(function()
    local Character = Pickaxe.Parent
    local Humanoid = Character.Humanoid
    local Animator = CheckAnimator(Humanoid)
    
    if Animator.ClassName == "Animator" then
        local AnimationTrack = Animator:LoadAnimation(Animation)
        print("Pickaxe was activated")
        AnimationTrack:Play()
        print("Animation was played")
    end
end)
2 Likes

It still doesn’t work for some reason

That is very strange… is it even printing?

1 Like

Yes it prints I can send you a video if you want

Is it a group game? if so, the animation needs to be made by that group.

1 Like

It’s not a group game. I am just practicing my scripting skills so I really don’t know any potential fixes other than what i’ve already tried.

Here is a video of me trying it. Dunno if you can use it for much https://medal.tv/games/roblox-studio/clips/C8aG1zUzmkahR/d13374rHMBCR?invite=cr-MSxncUUsMjUzMjEwMzQs

Did you make the animation for R15 or R6? Maybe that could be the reason?

1 Like

I tried to make it for both, none of them work.

Is your animation priority lower than Action, it wont play properly.
Make sure your animation priority is “Action”, “Action2”, “Action3” or “Action4” any of these work!

1 Like

Ah it works now thank you. It was my first animation so it helped alot.

1 Like