Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a GUI invisible when you press a key?

I am trying to make a command bar and I am trying to make it disappear when I press a certain key code I used:

game:service'UserInputService'.InputBegan:connect(function(inputObject, gameProcessedEvent)
	if (inputObject.KeyCode == Enum.KeyCode.E) then
	game.StarterGui.ScreenGui.Input.Visible = true
	print("Test")
	end;
	end);

Also it's a local script in Replicated First

3 comments

0

Didnt you already post this?

0

Its been like 10 minutes, maybe try longer before asking for help.

0

The print function works and yes I did but I needed more help

1 answer

✓ Accepted answer

The issue here is that you're changing the Gui object in StarterGui. Once the character loads, contents of StarterGui are cloned into the respective player's PlayerGui folder. Therefore, we need to access the Gui from there. Additionally, :connect() and :service() are deprecated. Use :Connect() and :GetService(), respectively.

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

UIS.InputBegan:Connect(function(key,gameProc)
   if not gameProc then
      if key.KeyCode == Enum.KeyCode.E then
         local gui = player.PlayerGui:FindFirstChild("ScreenGui")
         if gui then
            gui.Input.Visible = true
         end
      end
   end
end)

##Accept and upvote if this helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.