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

UserInputService Shift Button Wont Work?

Asked by 6 years ago
Edited 6 years ago

So i was making an Sprint script by holding shift and i got this problem

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard.Shift then
    print("SHIFTttt")
    end
end)

I has the error Shift is not valid member

How did i do wrong? Tell me please

Useless i was trying with right - left shift thingy

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Shift is a part of KeyCode and you are using UserInputType which does not have a child called Shift which explain the error in this code ie There is nothing called Shift under Kyeboard.

The other issue is that you should be checking the KeyCode for the pressed key and include left of right shift

Example

local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        print("Left shift down")
    end
end)

Hope this helps

Ad
Log in to vote
0
Answered by 6 years ago

It's because Shift isn't a valid member of Keyboard, as the error says. Keyboard is used whenever a keyboard button is pressed. Instead you'd use KeyCode, then LeftShift or RightShift.

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
    print("SHIFTttt")
    end
end) 
0
Thanks! SunxLightz 30 — 6y

Answer this question