Why doesn't my GUI work when I press i?

  1. I want my GUI to be “Visible” when I press “i” on my keyboard.

  2. The GUI isn’t showing up when I press “i”, error isn’t showing up in the output logs or F9.

  3. I have tried using KeyDown, and other methods, and even searched on YouTube, but to no avail.

Here is my variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropItem = ReplicatedStorage:WaitForChild("DropItem")
local UserInputService = game:GetService("UserInputService")

wait(3)

local player = game.Players.LocalPlayer
local Inventory = player.Inventory

local MainGui = script.Parent
local InventoryGui = MainGui.InventoryGui
local InventoryImage = MainGui.InventoryImage

Code with issues

UserInputService.InputBegan:Connect(function(I, IsTyping)
	if IsTyping then return end
	local Keypressed = I.KeyCode
	if Keypressed == Enum.KeyCode.I then
		InventoryGui.Visible = true
		InventoryImage.Visible = true
	end
end)

UserInputService.InputEnded:Connect(function(I, IsTyping)
	if IsTyping then return end
	local Keypressed = I.KeyCode
	if Keypressed == Enum.KeyCode.I then
		InventoryGui.Visible = false
		InventoryImage.Visible = false
	end
end)

this is apart of a larger inventory script, if necessary ill post it in the comments.

Thank you for your time!

1 Like

I’d suggest u use WaitForChild while declaring ur UI components in case the UI doesn’t load in.

1 Like

By chance, are you testing this in Studio? I’ve run into a few issues using UserInputService with “O” and “I”, because in Studio these keys are used to zoom in and out in play test sessions. Try changing this to Enum.KeyCode.E and press E instead and see if anything changes.

Enum.KeyCode.I will work in live games, just not Studio.

4 Likes

This might be the problem, i’ve encountered this a few weeks ago.

Thank you, ill implement that right now.

Thank you, this seems to be the issue.