My hold animation keeps stopping

I created a gun and added a hold animation that runs each time you equip it. Apparently, the animation keeps stopping and replaying; each at random intervals.

--<< Variables >>--

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer

--<< Folders >>--

local animations = tool:WaitForChild("Animations")

--<< Animations >>--

local holdAnim = animations:WaitForChild("Hold")

--<< AnimTracks >>--

local holdTrack

--<< Functions >>--

local function equip()
	local character = player.Character or player.CharacterAdded:Wait()
	
	if character then
		local humanoid = character:WaitForChild("Humanoid")
		
		holdTrack = humanoid:LoadAnimation(holdAnim)
		holdTrack:Play()
	end
end

local function unequip()
	warn("Unequipping!")
	if holdTrack then
		holdTrack:Stop()
	end
end

--<< Event Listeners >>--

tool.Equipped:Connect(equip)
tool.Unequipped:Connect(unequip)

Is your animation at the highest priority? By default animations are at the lowest priority meaning they will stop if something like the idle or walking animation play

1 Like