You can utilize both UserInputService.InputBegan and UserInputService.InputEnded signals to achieve this.
Something like this should work (assuming it’s a Frame).
local UserInputService = game:GetService("UserInputService")
local inventoryFrame = script.Parent -- Should be path to your inventory UI (should be a Frame)
UserInputService.InputBegan:Connect(function(input: InputObject, processed: boolean): ()
if processed then return end
if input.KeyCode ~= Enum.KeyCode.Q then return end
inventoryFrame.Visible = true
end)
UserInputService.InputEnded:Connect(function(input: InputObject, processed: boolean): ()
if processed then return end
if input.KeyCode ~= Enum.KeyCode.Q then return end
inventoryFrame.Visible = false
end)