Sprinting animation problem

Hey there, so im trying to make a sprint system and I run across a problem specifically in this spot:

	game:GetService("RunService").Heartbeat:Connect(function()
		if hum.MoveDirection.Magnitude > 0 and sprinting == true then
			spranim:Play()
			hum.WalkSpeed = 24
		else
			spranim:Stop()
			hum.WalkSpeed = 16
		end
	end)
		

The reason why i use a .Heartbeat statement is because the if statement isnt ran again so the code wont detect it.

The problem is, is that the sprint animation just looks like its one frame because its playing over and over again at the fastest speed ever.

Any help is appreciated.

i edited my post. sorry for that

Its all good, the reason it keeps playing one frame is because its playing the animation over and over again, you need to make a debounce so that if the animation is already playing. then it wont play the animation anymore

can you give an example on this? im sorry if i dont understand your reply.

its just another if statement, where if the animation is already playing it won’t continue to play it over and over. It will only play it, if it isn’t already being played

game:GetService("RunService").Heartbeat:Connect(function()
	if hum.MoveDirection.Magnitude > 0 and sprinting == true then
		if not spranim.IsPlaying then --if the animation isn't already playing 
			spranim:Play()
			hum.WalkSpeed = 24
		end
	else
		spranim:Stop()
		hum.WalkSpeed = 16
	end
end)

thank you so much bro, it worked!

1 Like

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