Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I detect if player is pressing Left Shift?

Asked by 2 years ago

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

Log in to vote
3
Answered by
9mze 193
2 years ago

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)
0
More information about UserInputService at https://create.roblox.com/docs/reference/engine/classes/UserInputService 9mze 193 — 2y
0
Additionally, if you’re trying to get the input to the server make sure you use a RemoteEvent. TheTrueLando 15 — 2y
Ad

Answer this question