Is it possible to make a variable = 2 enum.KeyCodes?

for example.

local Slot1 = nil
local Slot2 = nil
local Slot3 = nil
local Slot4 = nil

if uis.GamepadEnabled == true then
	--mokentroll user
	Slot1 = Enum.KeyCode.ButtonL1
	Slot2 = Enum.KeyCode.ButtonL2
	Slot3 = Enum.KeyCode.ButtonR1
	Slot4 = Enum.KeyCode.ButtonR2
else --can i do this??
	Slot1 = Enum.KeyCode.KeypadOne or Enum.KeyCode.One
	Slot2 = Enum.KeyCode.KeypadTwo or Enum.KeyCode.Two
	Slot3 = Enum.KeyCode.KeypadThree or Enum.KeyCode.Three
	Slot4 = Enum.KeyCode.KeypadFour or Enum.KeyCode.Four
end



uis.InputBegan:Connect(function(key)
	print(key)
	if key.KeyCode == Slot1 then
		print("s1")
		
		
	elseif key.KeyCode == Slot2 then
		print("s2")

		
	elseif key.KeyCode == Slot3 then
		print("s3")

		
	elseif key.KeyCode == Slot4 then
		print("s4")

		
	end
end)

--[[it doesnt throw any errors but it only works on the keypad enums
is there anyway to assign 2 enums to the same variable?

thanks in advance!]]


try using context action service

1 Like

I mean did you try if it works? It should because I have a code that uses that too.

i have used it before and you can set a function to work for more then one input

I tried it it only works for the 1st enum i put in
the keypad enums.

put

local

before the “Slot#” word, might help

1 Like

you can do something similar and much more efficient

local UIS = game:GetService("UserInputService")

local Tab = UIS.GamepadEnabled and {
	[Enum.KeyCode.ButtonL1] = function()
		--Do function
	end,
	[Enum.KeyCode.ButtonL2] = function()
		--Do function
	end,
	[Enum.KeyCode.ButtonL3] = function()
		--Do function
	end,
	[Enum.KeyCode.ButtonL4] = function()
		--Do function
	end
} 
	or 
{
	[Enum.KeyCode.One] = function()
		--Do function
	end,
	[Enum.KeyCode.Two] = function()
		--Do function
	end,
	[Enum.KeyCode.Three] = function()
		--Do function
	end,
	[Enum.KeyCode.Four] = function()
		--Do function
	end
}  
	
 

UIS.InputBegan:Connect(function(input,gpe)
	if gpe then return end
	
	if Tab[input] then
		Tab[input]()
	end
end)

1 Like