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)
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)
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)
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!