Tool animation not playing correctly

Just a simple attack animation when I use the tool. Whenever I’m holding the tool, the animation wont affect the arm it is on. The animation does play. It just doesn’t affect the arm when the tool is used.

Code:

local tool = script.Parent
local animation = tool.Animation

tool.Activated:Connect(function()
	print("activated")
	local char = tool.Parent
	local humanoid = char.Humanoid
	
	local lanim = humanoid:LoadAnimation(animation)
	lanim:Play()
	wait(0.5)
	tool.Woosh.Playing = true
	
end)

Problem:

Just adding one line to the script

local tool = script.Parent
local animation = tool.Animation

tool.Activated:Connect(function()
	print("activated")
	local char = tool.Parent
	local humanoid = char.Humanoid
	
	local lanim = humanoid:LoadAnimation(animation)
    lanim.Priority = Enum.AnimationPriority.Action
	lanim:Play()
	wait(0.5)
	tool.Woosh.Playing = true
	
end)

Try this, it just sets the animation’s Priority to ‘Action’ so that it can override all the current animations on your character.

References for you below:
https://developer.roblox.com/en-us/api-reference/enum/AnimationPriority
https://developer.roblox.com/en-us/api-reference/property/AnimationTrack/Priority

1 Like
local animation = tool.Animation

tool.Activated:Connect(function()
	print("activated")
	local char = tool.Parent
	local humanoid = char.Humanoid
	
	local lanim = humanoid:LoadAnimation(animation)
	lanim:Play()
	wait(0.5)
lanim:Stop()	
end)

or maybe

local animation = tool.Animation

tool.Activated:Connect(function()
	print("activated")
	local char = tool.Parent
	local humanoid = char.Humanoid
	
	local lanim = humanoid:LoadAnimation(animation)
	lanim:Play()
	wait(0.5)
	tool.Woosh.Playing = false
	
end)

It still doesn’t work. I’ve set the animation priority itself and on the script but the animation still wont play properly.

Animations with the priority on action should always override the default tool animation… Maybe for testing just try animating the left arm at the same time and see if that plays properly?

Please go to the Dev API before making a post.
Also humanoid:LoadAnimation() is Deprecated meaning it is not supported in new places.
Change the line

	local lanim = humanoid:LoadAnimation(animation)

to

	local lanim = humanoid.Animator:LoadAnimation(animation)

I support my case with
Animator | Roblox Creator Documentation,
Humanoid | Roblox Creator Documentation,
and Animator | Roblox Creator Documentation

Tried this. Still doesn’t work. The animation still gets overridden by other basic animations like walking or jumping.

Hello! Make sure to set the weld of the tool to the arm. I use qPerfectionWeld to keep the tool with the hand or body. Link

This is also the script I use for a “animate on click” animation. I would try using that and see if it fixes the problem, however it seems you want to animate right when the tool is out.

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
        animation:Play()
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)

Hope this helps in the long run!

1 Like

Thanks. I just wanted to clarify. I put the plugin linked in the tool like this:
image

and tried out your script (Local script) here:

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
		animation:Play()
	end)
end)

But still got no results. Just wanted to know if I did anything wrong.

EDIT: Never mind, I solved it. Your solution worked but I also had to change animation priority. Thanks.

Of course, glad I could assist! Good luck with your project!

1 Like