UserInputService not calling?

I am trying to make it so when you press a button with the around mid-2014 backpack, it will not call ActivateGear(num). The problem is: it’s not firing! I added prints to test it, but when I press 1 on my keyboard, it won’t call ActivateGear(num) or print(“1”). Here’s my code:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
	if key == Enum.KeyCode.One then
		activateGear(1)
		print("1")
	elseif key == Enum.KeyCode.Two then
		activateGear(2)
		print("2")
	elseif key == Enum.KeyCode.Three then
		activateGear(3)
		print("3")
	elseif key == Enum.KeyCode.Four then
		activateGear(4)
		print("4")
	elseif key == Enum.KeyCode.Five then
		activateGear(5)
		print("5")
	elseif key == Enum.KeyCode.Six then
		activateGear(6)
		print("6")
	elseif key == Enum.KeyCode.Seven then
		activateGear(7)
		print("7")
	elseif key == Enum.KeyCode.Eight then
		activateGear(8)
		print("8")
	elseif key == Enum.KeyCode.Nine then
		activateGear(9)
		print("9")
	elseif key == Enum.KeyCode.Zero then
		activateGear(0)
		print("0")
	end
end)

Any help will be greatly appreciated. Thanks!

It has to be key.KeyCode not just key.

1 Like

You need to check the keycode with key.KeyCode not just key, like so:

if key.KeyCode == Enum.KeyCode.One then .. end
2 Likes

You’re using the first parameter wrong. It’s a InputObject so you need to call it like so:

if key.KeyCode == Enum.KeyCode.One then

Reference:

1 Like

Thanks. I completely forgot about that.

Well now you know :slight_smile:. You should also maybe name the parameter to input because key is actually a misleading name and can cause issues like you just ran into.

1 Like

At the beginning of the function, define key by doing local key = key.KeyCode

3 Likes