Take this code for example:
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then --Also, could be written as [[inputObject.KeyCode == "R"]] print("R was pressed") end end)
From what I understand, every time a key is pressed, this function will fire and determine if the key pressed was R, and if it is, print that "R was pressed". My question being;
can the function only fire if the R key is pressed?
would it still be required that every input is listened to?
Does listening to every input not really matter in terms of lag?
You're also able to create dictionaries of Enum.KeyCodes if you want to skip if-statements altogether if you're that keen on efficiency. There's no other way to listen for a specific key to my knowledge.
It’s not inefficient, this is the best way you can go about listening for keys, it will fire with every key press and thats why you need the if statements but its impossible to listen to a specific key on roblox, so this is the best way to go about it.