Animation not working

I created an animation you know, and it’s supposed to let the character hold a cart with both hands, so it plays whenever a tool is equipped. But the thing is the animation is not playing. Could someone please help? No error message.

Local Script:

local cart = script.Parent

cart.Equipped:Connect(function(Mouse)
	local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
	Mouse.Button1Down:Connect(function()
		animation:play()
		print("played")
	end)
	cart.Unequipped:Connect(function()
		animation:Stop()
	end)
end)

check your animation priority
try adding this line below the “animation:Play()”

animation.Priority = Enum.AnimationPriority.Action

P.S. Humanoid:LoadAnimation() is deprecated and you should use that function on an Animator object (which you can find in a humanoid)

It prints Played but doesn’t do the animation.

Updated script:

local cart = script.Parent

cart.Equipped:Connect(function(Mouse)
	local animation = game.Players.LocalPlayer.Character.Humanoid.Animator:LoadAnimation(script.Parent.Animation)
	animation:play()
	animation.Priority = Enum.AnimationPriority.Action
	print("played")
	cart.Unequipped:Connect(function()
		animation:Stop()
	end)
end)

I forgot to make it so I didn’t have to click, but it still doesn’t work.

cart.Unequipped should not be inside .Equipped connection, that could be the issue? idk

local cart = script.Parent
local animation
cart.Equipped:Connect(function(Mouse)
	animation = game.Players.LocalPlayer.Character.Humanoid.Animator:LoadAnimation(script.Parent.Animation)
	animation:Play()
	animation.Priority = Enum.AnimationPriority.Action
	print("played")
end)
cart.Unequipped:Connect(function()
	if animation then animation:Stop() end;
end)

edit: it’s not a server script is it?

Still doesn’t change anything. It’s a local script.

I’ve edited the post above, plz try again
It’s not a server script is it? did you make the animation? is it a group game? does your game use r15 rigs or r6 rigs?

Still nothing, and no it’s a Local Script.

Try loading the character outside the function, you might be running this function before the character has a chance to load in.

Per roblox docs:
The Animator object must be initially created on the server and replicated to clients for animation replication to work at all. If an Animator is created locally, then AnimationTracks loaded with that Animator will not replicate.

Both Humanoid:LoadAnimation and AnimationController:LoadAnimation will create an Animator if one does not already exist. When calling LoadAnimation from LocalScripts you need to be careful to wait for the Animator to replicate from the server before calling LoadAnimation if you want character animations to replicate. You can do this with WaitForChild(“Animator”).

I’ve tried the code you’ve originally posted (mine too) and they all work fine. Your issue is 100% in the animation you’re trying to play. Make sure the animation is uploaded by the group (if you’re editing a group game). Or make sure it was uploaded by your account. Try replacing the animation ID with this 4940563117 (a roblox emote) and it will start working (for R15 characters).