Animation isn't playing

Making a sword that has a animation when it is activated, Sadly it isn’t working
Script:

local Tool = script.Parent
wait(1)
local Animation = Tool.Slash1
local Player = game.Players
local LocalPlayer = Player.LocalPlayer
local Char = LocalPlayer.Character
local Humanoid = Char:WaitForChild("Humanoid")
local AnimationTrack = Humanoid:LoadAnimation(Animation) --Animations, Important
local debounceTime = 1

Tool.Activated:Connect(function()
	AnimationTrack:Play()
	print("Playing")
end)
1 Like

Is there anything in output Make sure to check if there is Humanoid and Animation and everything is correct

Make sure you set the animation priority to action.

1 Like

Set the Priority to Action, as said by @Z_lqify :

local Tool = script.Parent
wait(1)
local Animation = Tool.Slash1
local Player = game.Players
local LocalPlayer = Player.LocalPlayer
local Char = LocalPlayer.Character
local Humanoid = Char:WaitForChild("Humanoid")
local AnimationTrack = Humanoid:LoadAnimation(Animation) --Animations, Important
local debounceTime = 1
AnimationTrack.Priority = Enum.AnimationPriority.Action

Tool.Activated:Connect(function()
	AnimationTrack:Play()
	print("Playing")
end)
1 Like

No any errors are showing apparently and yeah I did define everything correctly

As a side note, Humanoid:LoadAnimation() is deprecated.

Use Animator:LoadAnimation() instead, e.g.:

local animator = Humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(YOUR_ANIMATION)
animationTrack:Play()

BTW, I can’t immediately see any problems with your code, so perhaps it is to do with your animation instance, Slash1. Perhaps try replacing it with another animation to see if that’s the problem.

2 Likes

It might be an issue with the animation itself. Check your animation and make sure the AnimationId is correct.

1 Like

That was indeed the main case the id was incorrect

1 Like