Animation script not working

Hello! I’m scripting an animation but is not working, when i click with my tool equipped, it doesn’t play the animation,
here’s the code:

local Character
local player 

local ScriptsFolder = script.Parent
local Tool = ScriptsFolder.Parent
local AnimationFolder = Tool:WaitForChild("AnimationFolder")

local PunchAnimation = AnimationFolder:WaitForChild("PunchAnim")
local PunchAnimTrack

local Cooldown = false
local CooldownWait = 0.5

Tool.Activated:Connect(function()
	Character = Tool.Parent
	player = game:GetService("Players"):GetPlayerFromCharacter(Character)
	
	local Humanoid = Character:FindFirstChild("Humanoid")
	
	if Humanoid then
		PunchAnimTrack = Humanoid:LoadAnimation(PunchAnimation)
	end
end)


Tool.Equipped:Connect(function()
	if Cooldown == false then
		Cooldown = true
		
		PunchAnimTrack:Play()
		
		wait(CooldownWait)
		Cooldown = false
	end
end)

red_part

Did i index something wrong?

hey!

you should probably make sure that the punch animation’s AnimationPriority is set to Action or higher, which you can do when exporting the animation.

also, it’s better to load animations from the Animator instance rather than the Humanoid as it is deprecated.

You are getting the PunchAnim Track when the player uses the tool and you equip the tool first so your animation won’t play, either change on how you get the AnimationTrack or you get the animation track when the player equips it and play it when they equip it

1 Like