I am trying to stop the animation when the tool is unequipped.


It works normally, but if you unequip the tool while the equip animation is playing, you will get stuck in the idle animation. (that plays right after equip animation)
I’d like to hear suggestions on how I could resolve this problem.
Here is a sample of my code:
local reloadAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Reload"))
local idleAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Idle"))
local holsterAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Holster"))
local fireAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Fire"))
local equipAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Equip"))
local findAmmoGui
local function equip()
local duplicate = gui:Clone()
duplicate.Parent = player.PlayerGui
findAmmoGui = player.PlayerGui:FindFirstChild("GlockAmmoGui")
sounds.Equip:Play()
weaponModule.onEquip()
equipAnimationPreload:Play()
findAmmoGui.MainFrame.AmmoLeft.Text = ammo
findAmmoGui.MainFrame.MaxAmmo.Text = maxAmmo
wait(equipAnimationPreload.Length)
equipAnimationPreload:Stop()
idleAnimationPreload:Play()
game.StarterPack:SetAttribute("running", true)
end
local function unequip()
weaponModule.onUnequip()
weaponModule.unAim()
findAmmoGui = nil
reloadAnimationPreload:Stop()
idleAnimationPreload:Stop()
holsterAnimationPreload:Stop()
fireAnimationPreload:Stop()
equipAnimationPreload:Stop()
game.StarterPack:SetAttribute("running", false)
end