I'm currently making a new game and I want the player to be able to press keys to trigger events. One of the things I want to add is hotbar access via 1-9 keys. Something simple to do is just copy and paste the key detection code over and over, but I want it to take up less space and so I can change what key pressing does easily. So I made this-
local keyList = {'One','Two','Three','Four','Five','Six','Seven','Eight','Nine'}
function onKeyPress(inputObject, gameProcessedEvent)
for i=1,9 do
print(inputObject.KeyCode,"Enum.KeyCode." .. keyList[i])
if inputObject.KeyCode == "Enum.KeyCode." .. keyList[i] then
print(keyList[i] .. " pressed")
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
But it does nothing, not even throw an error, even though they look exactly the same. I don't know what is going on, the wiki is no help and the Roblox forums are offline forever. Any suggestions on what to do?

1 comment
Thanks so much dude, I got stuck searching for the wrong thing for so long that I didn't even know this existed!