UserInputService not registering a key press (in studio)

I have made it so that when you press “I” it opens the gui(even copied from user input service page)

It works with probably any button(since i tested it on button R), but it somehow doesnt work with button I.
I think that button I is reserved by core script, and if so, please tell me how to avoid that(the game is locked to first person).
Here’s the script:

local inputService = game:GetService("UserInputService")
local db = false
local selecTab = game.Players.LocalPlayer.PlayerGui.Inventory.Menus.SelectionTab
local itemTab = game.Players.LocalPlayer.PlayerGui.Inventory.Menus.ItemTab
local originPos = selecTab.openedornah

local function getKey(input, Processed)
	print("function ran")
	if not Processed then
		if (inputService:GetFocusedTextBox()) then
			print("player typed 'i' when chatting in chat bar")
			return; -- player's not chatting
		end
		if input.KeyCode == Enum.KeyCode.I then
			print("got key finally")
			if db == false and originPos.Value == false then
				print("executing the script")
				db = true
				originPos.Value = true

				itemTab:TweenPosition(UDim2.new(0.572, 0,0.226, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.7)
				selecTab.badges.TextLabel.Visible = false
				selecTab.inventory.TextLabel.Visible = false
				selecTab.settings.TextLabel.Visible = false

				wait(2)
				db = false
			elseif originPos.Value == true then
				print("got key finally")
				db = true
				originPos.Value = false

				itemTab:TweenPosition(UDim2.new(1, 0,0.226, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.7)
				selecTab.badges.TextLabel.Visible = true
				selecTab.inventory.TextLabel.Visible = true
				selecTab.settings.TextLabel.Visible = true

				wait(2)
				db = false
			end
		end
	end
end

inputService.InputBegan:connect(getKey)

To anyone that’s having the same issue:

The keycode I is reserved by Roblox, therefore you would have to disable it in order to manipulate it however you want.
You can switch to another keycode if possible, but, if you need to set it as I, then check out the following:

ContextActionService
ContextActionService:UnbindAction()

You can use ContextActionService:UnbindAction("action name here wooo") to remove the action that roblox has reserved.
But, some actions can not be changed, since they’re reserved by CoreGui.

Read here which actions you can bind or not: Mouse and Keyboard | Roblox Creator Documentation

1 Like