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

1local UIS = game:GetService("UserInputService")
2local player = game.Players.LocalPlayer
3 
4UIS.InputBegan:Connect(function(input)
5    if input.UserInputType == Enum.UserInputType.Keyboard.Shift then
6    print("SHIFTttt")
7    end
8end)

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

1local UIS = game:GetService("UserInputService")
2local player = game:GetService("Players").LocalPlayer
3 
4UIS.InputBegan:Connect(function(input)
5    if input.KeyCode == Enum.KeyCode.LeftShift then
6        print("Left shift down")
7    end
8end)

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.

1local UIS = game:GetService("UserInputService")
2local player = game.Players.LocalPlayer
3 
4UIS.InputBegan:Connect(function(input)
5    if input.KeyCode == Enum.KeyCode.LeftShift then
6    print("SHIFTttt")
7    end
8end)
0
Thanks! SunxLightz 30 — 6y

Answer this question