How to create a customizable keybind system

This is my current idea of doing it but I am wondering if there is a better method

local Services = {
	["UserInputService"] = game:GetService("UserInputService"),
}


local Keybinds = {
	["Attack1"] = Enum.UserInputType.MouseButton1,
	["Attack2"] = Enum.UserInputType.MouseButton2,
	["Ability1"] = Enum.KeyCode.Q,
	["Ability2"] = Enum.KeyCode.E,
}


local function setupkeybinds()
end

local function getbind(input)
	local bind = nil 
	
	for i,v in Keybinds do 
		if input.UserInputType == v or input.KeyCode == v then
			bind = i 
		end
	end
	
	return bind 	
end

local function oninputbegan(input)
	local bind = getbind(input)
	if bind then 
		print(bind)
	end
end

Services.UserInputService.InputBegan:Connect(oninputbegan)
1 Like