Why is sprint breaking when doing another key, such as jumping..?

A very simple issue; my sprinting stops when I jump, and may also do it if I add a crouch function… how do I fix this?

--[[ Input Began Console ]]
UIS.InputBegan:Connect(function(inputKey)
	if UIS:GetFocusedTextBox() == nil then
		if inputKey.UserInputType == Enum.UserInputType.Keyboard then
			if inputKey.KeyCode == Enum.KeyCode.Quote then --[[Command Bar Pop-up, Quotation Key]]
				warn("ye")
			end
			if inputKey.KeyCode == Enum.KeyCode.LeftShift then --[[Shift-lock, Left Shift Key]]
				game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
			end
		elseif inputKey.UserInputType == Enum.UserInputType.MouseButton1 then --[[Left Click]]
			
		elseif inputKey.UserInputType == Enum.UserInputType.MouseButton2 then --[[Right Click]]

		elseif inputKey.UserInputType == Enum.UserInputType.MouseButton3 then --[[Scroll Wheel Click]]

		end
	end
end)

UIS.InputEnded:Connect(function(inputKey)
	if UIS:GetFocusedTextBox() == nil then
		if inputKey.UserInputType == Enum.UserInputType.Keyboard then
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		end
	end
end)
3 Likes

InputEnded checks if any keys input ended. So when you’re sprinting and press spacebar to jump, on the spacebar release it registers as InputEnded, runs the code and then sets the walkspeed to 16 because it doesn’t know which key got pressed.

Change the InputEnded function to this:

UIS.InputEnded:Connect(function(inputKey)
	if UIS:GetFocusedTextBox() == nil then
		if inputKey.KeyCode == Enum.KeyCode.LeftShift then --[[Shift-lock, Left Shift Key]]
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		end
	end
end)
2 Likes

oh my god, how did I not notice that… thank you!

1 Like

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