Tool animation wont play

Hello DevForum!
Today I am trying to get a drinking animation to play when a tool is used. The script is not working and nothing is coming up in the output or script analysis areas. Linked below are both the script and a picture of the starterpack. Thanks for reading!

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

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

Screenshot 2022-06-29 120508

1 Like

If you want to detect when the player uses the tool, use tool.Activated (doc)

script.Parent.Activated:Connect(function()
	animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Drink)
	animation:Play()
end)

The animation still is not playing when I activate the tool, I have tried changing it to multiple different keybinds as well.

What kind of animation is that? Is it yours? What animation priority does it have?

Try putting a print(xyz) after the Activated event. And if it doesn’t print, it isn’t a problem with the script

It is a drink animation, I created the animation and the animation priority is set to action. When the tool is activated it is printing xyz in the output.

script.Parent.Activated:Connect(function()
	print("xyz")
	animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Drink)
	animation:Play()

end)

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

Is this the whole script? If it is, the problem is that you don’t have an “animation” variable and you have to create. Just put local animation at the beginning of the script

Is this correct? I just ran this script and the animation still doesn’t work. This is the whole script.

local animation
script.Parent.Activated:Connect(function()
	print("xyz")
	animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Drink)
	animation:Play()

end)

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

I recommend not using Humanoid:LoadAnimation() because it is now deprecated. You can use Humanoid.Animator:LoadAnimation() instead.

Anyways, what is the AnimationPriority (set when creating animation)? It should be set to Action.

Updated the script, doesn’t appear to work. When I created the animation the animation priority was set to action.

I thought maybe the priority was the problem but looks like it isn’t. If there are no errors and the print works, I have no idea why it won’t play.

And the Humanoid:LoadAnimation might be marked as deprecated, but it still works for me

What happens if you do this from a server script?

When you mean server script, do you mean this?
Screenshot 2022-06-29 125329
I did this and still isn’t working

Exactly. It’s always a question to ask yourself when wanting to play an animation.
“Do I play it on the client or server?”

In this case I think you want it on the server.

Usually this happens if the owner of the Animation is not the same owner of the game. If this is a group game make the animation creator/owner the group. Also sometimes animation doesn’t play when you test in studio, try to test it in the actual game.

Hello! I am the owner of both the game and the animation. I have also tried testing this in the actual game, it does not work.

Is the game owner your group? If so, you need to upload the animation to your group.

My profile is the owner of the game and animation.

i would try using the animation ID instead of the actual “Animation” instance

Hi! I tried doing this! Here is the new script I made, it still doesn’t work.

script.Parent.Activated:Connect(function()
	print("Playing Animation")
	local player = game.Players.LocalPlayer
	local Animation = Instance.new("Animation", player.Character)
	print("Got to line 5")
	Animation.AnimationId = "rbxassetid://10098178988"
	print("Got to line 7")
	local AnimationLoaded = player.Character.Humanoid:LoadAnimation(Animation)
	print("Got to line 9")
	AnimationLoaded:Play()
	print("You finished")
end)

At the moment all of the print statements are showing up in the output.

First of all, no, you do not need to parent the Animation to the character.
Second of all, no, it is not necessary to do this from a LocalScript (but it should still work).

Third of all, have you tested an animation that Roblox uploaded?