You can create a dictionary with the keyboard input as the key, and a function as the value, like so:
local UserInputService = game:GetService("UserInputService")
local userInputDictionary = {
["A"] = --some random func,
["B"] = --some random func
}
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
userInputDictionary[keyPressed] -- this line will invoke the func --
end
end)
-- modulescript
local InputDictionary = {
["A"] = function()
}
return InputDictionary
-- localscript
local InputDictionary = require(path.to.dictionary)
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
InputDictionary[keyPressed] -- this line will invoke whatever is in the dictionary
end
end)