How to make animation from stopping when I move

Make it so when you swing and move you don’t run and block the hit animation from playing

local activeSwing = false

tool.Activated:Connect(function()
	if justPulledOut == false and swingDelay == false then
		activeSwing = true
		Hit:Play()
		Idle:Stop()
		run:Stop()
        wait(1)
		activeSwing = false
	end
end)

while true do
	wait(0.2)
	if active == true and activeSwing == false then
		char.Humanoid.Running:Connect(function(speed)
			if speed > 5 then
				print("Running")
				run:Play()
				Idle:Stop()
			elseif speed < 5 then
				run:Stop()
				Idle:Play()
			end
		end)
	end
end

Thank you.

1 Like

So how far have you gotten? Are you having a problem with your script not working like that, or are you just trying to find a way to add that to it?

nah it works just the running animation plays when I walk but I am attacking which shouldn’t happen.

Replace the while true do with this:

char.Humanoid.Running:Connect(function(speed)
	if active == true and activeSwing == true then
		if speed > 5 then
			print("Running")
			run:Play()
			Idle:Stop()
		elseif speed < 5 then
			run:Stop()
			Idle:Play()
		end
	end
end)

The reason it’s playing a running animation while you move is because when you aren’t swinging, it connects to the humanoid whenever it runs, but it won’t stop being connected unless you disconnect it. Meaning once you’re not swinging, it’ll always make you play an animation when running. This makes it so that it connects only once, and checks if they aren’t swinging