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

UserInputService Shift Button Wont Work?

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

✓ Accepted answer

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

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) 

1 comment

0

Thanks!

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