I'm working on a template userinput script and I can't figure out how to make it use a string/variable for the KeyCode. I want to make my game customizable w/ the keybinds and have no idea how to get this to work. Is it possible to even use variables for UserInput?
local userInputService = game:GetService("UserInputService")
local plyr = game.Players.LocalPlayer
local pgui = plyr.PlayerGui
local bpack = plyr.Backpack
local enabled = true
local key = script.Parent.Value -- Value is "One", for the 1 key.
userInputService.InputBegan:connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == key then -- Key is the string
print("Variable key was pressed!")
end
end)
Anyways my question is, is this possible and if so how?

1 comment
I find this very interesting as I would like to know how to do this aswell. I feel like wiki doesn't explain enough sometimes