Animation Does Not Stop

Hi all,

I’m working on a melee weapon. When the tool is equipped, a holding animation is played and when it’s unequipped, the holding animation stops. Here’s what I’ve done so far:

local idleTrack

Tool.Equipped:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	Handle.EquipSound:Play()
	if Humanoid then
		local equippedAnim = Config.Animations:FindFirstChild("EquipAnim")
		if idleTrack==nil then
			idleTrack = Humanoid.Animator:LoadAnimation(Config.Animations.IdleAnim)
		end
		if equippedAnim then
			local equipTrack = Humanoid.Animator:LoadAnimation(equippedAnim)
			equipTrack.Looped = false
			equipTrack:Play()
			equipTrack.Ended:Wait()
		end
		if Tool.Parent == Character then
			idleTrack:Play()
		end
	end
end)

Tool.Unequipped:Connect(function()
	if idleTrack~=nil then
		idleTrack:Stop()
		print("Track stopped")
	end
end)

This is only an excerpt of the code, all the variables are defined.

The holding animation works fine:
image

However, when I unequip the tool, the animation does not stop even though the output prints "Track stopped" as instructed in the code:
image

What is the problem here, how can I fix this? There is no error in the output.

Thanks in advance!

1 Like

make sure you are stopping a good animation, please try this and tell me if it worked

local character = game.Players.pazdanmichal2.Character --here put ur own nick
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")

for _,AnimTrack in pairs(animator:GetPlayingAnimationTracks()) do
	AnimTrack:Stop()
end

also i found this in a different topic so if my script didn’t work please read this :))
here is a topic

After almost a year later, I have finally came up with a solution.

The animation playing script was server-sided (the script stated in topic post), triggered by LocalScripts, because I believe animations played locally would not play for other players, which I later found wrong. The issue about the script is that it loads new animations every time it is called, thus making it does not stop the animation playing, instead it stops the new one that was loaded in which it wasn’t even played yet. I later rewrote the script, playing animations in LocalScript (which actually plays the animation for other players somehow) and other server-sided tricks goes into the server-sided script, which makes the animation playing no longer an issue.

The game has been resurrected now. I appreciate all the attempts to help in the past, it is purely my fault for I did not state the problem and everything clear. I hope this bump can help new scripters somehow.

It turns out the problem is actually equipTrack.Looped = false because that line quite literally did nothing. So the equipTrack.Ended:Wait() would never end and the animation was a loop of 1 keyframe line.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.