What is the best keybind for sprinting, excluding Left Shift? (Shift Lock Switch is used)

I am trying to add a running mechanic to the newest game I am working on, but I don’t want to keybind it to the Left Shift key, as it is used for the Shift Lock Switch, which will be useful in some parkour elements.

I attempted to bind it to the Left Control key, but after doing so, it did not detect anything, also not going to use Caps Lock for it as I don’t want the player to switch from capital to normal letters every time they attempt to sprint, and Tab is simply too high for the pinky finger to reach it comfortably, not even sure if any of these would be detected either.

I attempted binding it to some of the QWERTY or number keys, but it would make using the WASD a lot harder, as you have to hold the key down in order to sprint, which means you wouldn’t be capable of moving in one of the directions while sprinting.

Later I thought of binding it to one of the keys near the Spacebar (Like C), which would make it possible to press the sprint key with your thumb, but once again, since you have to hold it, it would make jumping harder for unskilled hands, which brings many problems, you may press the spacebar too late and fall off the platform, or accidentally let go of the sprint key, which will slow you down and you may not reach the platform either, but if your thumb will get used to this kind of use, it could work.

Lastly, I thought of using one of the mouse buttons, of course left and right mouse button already have a use, since the game can be played in third person, so the only option is the scroll wheel button, but Roblox itself doesn’t have the button even programmed into it, since some mouses don’t have these buttons, and laptop touch pads don’t have it either.

So in conclusion, I am really out of options, and cannot find a sprint script which would require you to only press a button instead of holding it down, is there anyone who has more knowledge about such things and knows which key I could use that I didn’t think of?

Also, it won’t be a problem on an XBOX controller, there should be enough free buttons on it to program it in, I hope so atleast.

1 Like

What about double tapping the w key to “enable” sprinting and then as soon as the character stops moving sprinting is disabled.

2 Likes

Would be great if I will find a script which works like that, sadly I don’t have enough experience with this area of programming to make such a thing.

Pressing W two times or just pressing LCtrl

1 Like

Tried it with Left Control, but for some reason it is not working, maybe it is turned off on my computer and I don’t know about it, or it simply doesn’t work on studio, but would work in a normal game, I’ll have to check that option.

Here is the very simple code which would allow you to do the double tapping the w key (local script btw):

UIS = game:GetService("UserInputService")

last_tick = 0

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		
		local time_difference = tick() - last_tick

		if time_difference > 0.1 and time_difference < 0.3 then
			--send remote to server
		end
		
		last_tick = tick()
	end
end)

It just checks for the last time the w key was pressed and if the last time it was pressed was between 0.1 and 0.3 seconds then you just send a remote to the server.

1 Like

I would probably recommend:
shift + numLK + Q

It‘s easy, fast and reliable for new players, and most of all, laptop friendly.

1 Like

I see, that would be really useful! How would I implement it with the code I am currently using tho?

local mouse = game.Players.LocalPlayer:GetMouse()
local running = false

function getTool()	
	for _, kid in ipairs(script.Parent:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end


mouse.KeyDown:connect(function (key) -- Run function
	key = string.lower(key)
	if string.byte(key) == 118 then
		running = true
		local keyConnection = mouse.KeyUp:connect(function (key)
			if string.byte(key) == 118 then
				running = false
			end
		end)
		for i = 1,5 do
			game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
			wait()
		end
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
		repeat wait () until running == false
		keyConnection:disconnect()
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		for i = 1,5 do
			game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
			wait()
		end
	end
end)

Also the importer for this code.

function onPlayerEntered(player)
	repeat wait () until player.Character ~= nil
	local s = script.SprintScript:clone()
	s.Parent = player.Character
	s.Disabled = false
	player.CharacterAdded:connect(function (char)
		local s = script.SprintScript:clone()
		s.Parent = char
		s.Disabled = false		
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

Ok there are quite a few things I changed so have a look at the comments in the code.

local UIS = game:GetService("UserInputService")   -- Mouse Key Events are deprecated so use User Input Service Instead.
local running = false
last_tick = 0

function getTool()	
	for _, kid in ipairs(script.Parent:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end

UIS.InputBegan:Connect(function (key) -- Run function but now using UIS.
	
	if key.KeyCode == Enum.KeyCode.W then  -- I prefer to use key codes as they are easier to read.

		local time_difference = tick() - last_tick

		if time_difference > 0.1 and time_difference < 0.3 then
			running = true

			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
				wait()
			end

			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
			
            repeat wait () until game.Players.LocalPlayer.Character.Humanoid.MoveDirection.Magnitude == 0   -- Only using repeat until loop here now so we dont need the connection anymore

			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

			for i = 1,5 do
				game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
				wait()
			end
		end
		
		last_tick = tick()
	end
end)
2 Likes

I understand, I will check if the code works, guessing I should put it inside of the code importer like the previous code I used? I am really thankful for the help!

Yes, the code I sent is a replacement of the first code block in that your last reply. But nothing needs to change in the importer code (your second code block in that last reply) because the script will still be named the same.

1 Like

I understand, it appears to be working perfectly, I am thankful for the help, and really appreciate you did spend some of your time upgrading this code! I’ll use the previous code for XBOX controllers only, hopefully I won’t run into any other problems like this for some time, thank you again.

No problem thank you for giving me a challenge to solve!

1 Like