local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(Input,GPE) if not GPE then 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
local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(Input,GPE) if not GPE then if Input.UserInputType == Enum.UserInputType.Keyboard then 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:
local CAS = game:GetService("ContextActionService") local function Button(actionName, inputState, inputObj) if inputState == Enum.UserInputState.Begin then --this will make the code only run when you press it down, so it doesn't fire twice. print("hi") end end --CAS:BindAction must always be below the function in order to work CAS:BindAction("any name here", Button, true, "q") --the parameters needs the following in order: --string name --the name of the function you want it to bind --create a button for mobile players --key you want to bind