Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I detect if player is pressing Left Shift?

Hello, I've been making some crouch and sprint scripts but I just realised that my sprint script doesnt work:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
	if key == "leftshift" then
--my sprint script
	end
end)

When i change "leftshift" to key like "v" it does work

1 answer

✓ Accepted answer

Use UserInputService.

local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input, _gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			print("The left shift key has been pressed!")
		end
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

2 comments

0
0

Additionally, if you’re trying to get the input to the server make sure you use a RemoteEvent.

This discussion is preserved as it was. New answers, comments, and votes are closed.