How to reset animations

I’ve got this melee weapon with a durability code line. It works, but when it destroys itself after it’s durability has been used, it keeps the hold animation in another script. I’m not really sure how I can reset the animation…

if it helps, here’s the holdanimation script

--CONFIG----------------------------------------------------------
local holdanimationid = 7455443488 --Enter hold animation ID here

------------------------------------------------------------------

repeat wait() until game.Players.LocalPlayer.Character
local lp = game.Players.LocalPlayer
local sp = script.Parent
local debounce = true

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://" .. holdanimationid
local holdtrack = lp.Character.Humanoid:LoadAnimation(anim)



sp.Equipped:connect(function()
	holdtrack:Play()
end)

sp.Unequipped:connect(function()
	holdtrack:Stop()
end)
2 Likes

You can stop the animation before it is destroyed.

If that’s in a separate script, you can use Humanoid | Roblox Creator Documentation and AnimationTrack | Roblox Creator Documentation

old topic, but I got some important info: the solution

for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
	playingTracks:Stop()
end
16 Likes

Thank you so much, you solved my problem! (Edit: Nevermind, it’s deprecated)

Still works as of 2024 just like all animation methods on humanoids, the method should be used on the animator object though for new work.