My Sprint script is buggy

So, whenever I let go of any movement key my animation is still playing
I tried adding an else statement, but that doesn’t work either.

UserInputService.InputBegan:Connect(function(input,proc)
	if proc then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		isSprinting = true
		humanoid.WalkSpeed = sprintWalkSpeed
		if humanoid.MoveDirection.Magnitude > 0 then
			runAnim:Play()
			while	isSprinting do
				task.wait(0.25)
				Stamina.Value += -1
			end
			while isSprinting == false do
				task.wait(.5)
				Stamina.Value += 1
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input,proc)
	if proc then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		isSprinting = false
		runAnim:Stop()
		humanoid.WalkSpeed = defaultWalkSpeed
	end
end)

In the example video, are you still holding shift? Your Animation is only set to stop when the Shift Key is let go, not when your character stops moving. If you the animation to stop when you stop moving you’ll need an additional connection there.

I would consider encasing it all in one big heartbeat that constantly checks for new events and disonnecting that heartbeat and clearning up when you let go.

2 Likes

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