I'm stuck on how to find when a player presses a button like "G" or anything
✓ ANSWER ACCEPTED
What is the event for when someone pushes a button?
2 answers
✓ Accepted answer
We need to use ContextActionService For input or even UserInputService
local cas = game:GetService("ContextActionService")
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then -- gets the input
print("R was pressed")
end
end
cas:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)
On the final line of code It does the function when you press R on your keyboard You can change Enum.KeyCode.R to What key you want(ex. Enum.KeyCode.Z)
You can use UserInputService.
For ex you can write :
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(Input)
local KeyCode = Input.KeyCode
if KeyCode == Enum.KeyCode.G then
print("G was pressed")
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Let me know if this helped :)
This didn't work, on then it says it must have identifier
Oh sorry i forgot to add a if. It should work now