Help on anmation script

I am trying to animate my food, however, when I click it, it won’t play the animation until I unequip it. Here’s my code.
My animation is under group inventory, under group game.

	Mouse.Button1Down:Connect(function()
		local animator = game.Players.LocalPlayer.Character.Humanoid:FindFirstChildOfClass("Animator")
		if animator then
			animationTrack = animator:LoadAnimation(script.Parent.Animation)
			animationTrack:Play()
			return animationTrack
		end
	end)


end)

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

Can’t you just use the Activated event instead of detecting for the Mouse?

script.Parent.Activated:Connect(function()
    local animator = game.Players.LocalPlayer.Character.Humanoid:FindFirstChildOfClass("Animator")
	if animator then
		animationTrack = animator:LoadAnimation(script.Parent.Animation)
		animationTrack:Play()
		return animationTrack
	end
end)
1 Like