local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.F then -- Enum.KeyCode.F => Replace F With Your Key
print("You pressed F")
end
end)
Keep in mind that they will also fire if it’s processed by the game (ex: chat), a workaround is really simple
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(funciton(input,gameProcessed)
if not gameProcessed then
-- it was not processed by the game meaning it's not chat or a textbox for example
-- input is an input object, read more about it here https://developer.roblox.com/en-us/api-reference/class/InputObject
end
end)