Animation not stopping using :Stop()

Hello, i have walking animation for my viewmodel. And when i walk, it starting playing animation. But when i stop, animation not stopping.
Script:

script.Parent:WaitForChild("Equiped").Event:Connect(function(arms)
	player.Character.Humanoid.Changed:Connect(function()
		local runninganim = arms.Humanoid:LoadAnimation(arms.Animations.WalkAnim)
		if arms then
			if player.Character.Humanoid.MoveDirection.Magnitude > 0 then
				if not runninganim.IsPlaying then
					print("Play")
					runninganim:Play()
					runninganim:AdjustSpeed(0.25)
				end
			elseif player.Character.Humanoid.MoveDirection.Magnitude <= 0 then
				print("Stop") -- printing but animation isn't stopping
				runninganim:Stop()
			end
		end
	end)
end)

I don’t know where is problem

You are creating a new runninganim everytime the Humanoid.Changed event fires.
Easiest fix would be:

local runninganim
script.Parent:WaitForChild("Equiped").Event:Connect(function(arms)
	player.Character.Humanoid.Changed:Connect(function()
		if not runninganim then runninganim = arms.Humanoid:LoadAnimation(arms.Animations.WalkAnim) end
		if arms then
			if player.Character.Humanoid.MoveDirection.Magnitude > 0 then
				if not runninganim.IsPlaying then
					print("Play")
					runninganim:Play()
					runninganim:AdjustSpeed(0.25)
				end
			elseif player.Character.Humanoid.MoveDirection.Magnitude <= 0 then
				print("Stop") -- printing but animation isn't stopping
				runninganim:Stop()
			end
		end
	end)
end)

Yes, and runninganim playing everytime. You script seems to be working, but currently i can’t test it. Thank you, i really don’t know how to fix it.

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