1 | local UIS = game:GetService( "UserInputService" ) |
2 | UIS.InputBegan:Connect( function (Input,GPE) |
3 | if not GPE then |
4 | if Input.KeyCode = = Enum.KeyCode.Q then |
it shows a error that the input object has no keycode? wtf.
try this and tell me if it works
1 | local UIS = game:GetService( "UserInputService" ) |
2 | UIS.InputBegan:Connect( function (Input,GPE) |
3 | if not GPE then |
4 | if Input.UserInputType = = Enum.UserInputType.Keyboard then |
5 | if Input.KeyCode = = Enum.KeyCode.Q then |
if you're not trying to make anything too advanced, i would recommend using ContextActionService, it's a bit more simple, and your keycode won't run if you're typing in chat.
example:
01 | local CAS = game:GetService( "ContextActionService" ) |
02 |
03 | local function Button(actionName, inputState, inputObj) |
04 | if inputState = = Enum.UserInputState.Begin then --this will make the code only run when you press it down, so it doesn't fire twice. |
05 | print ( "hi" ) |
06 | end |
07 | end |
08 |
09 | --CAS:BindAction must always be below the function in order to work |
10 |
11 | CAS:BindAction( "any name here" , Button, true , "q" ) |
12 |
13 | --the parameters needs the following in order: |
14 |
15 | --string name |
16 | --the name of the function you want it to bind |
17 | --create a button for mobile players |
18 | --key you want to bind |