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

How do I change the visibility of a GUI with a keyboard input?

I've wrote a previous script before this one and both haven't worked for me. The script and input runs through and does the print("") function but the GUIs disappear.

I've tried everything I could and nothing seems to work so I'm asking for help here.

Here is the script:

-- Main Variable --

local Menu = game.StarterGui.ScreenGui.MenuGUI
local plr = game.Players.LocalPlayer

-- Sub Menu Variables --

local Profile = Menu.Profile
local Friends = Menu.Friends
local Messages = Menu.Messages
local Location = Menu.Location
local Settings = Menu.Settings

-- Profile Image Variable --

local PFP = Menu.PlayerProfile

-- Input Variables --

local UIS = game:GetService('UserInputService')
-- Change GUI Position --

-- E to activate GUI -- 

plr:GetMouse().KeyDown:Connect(function(K)
	if K == "e" then
		Profile.Visible = false
		Friends.Visible = false

		print("Menu GUI Deactivated")
	end
end)

All of the variables are organized and I've made sure that they were correct but I've tried changing inputs and making it a thing that happens when joining but it doesn't work.

I was trying to link a link to the image of the folder but I can't figure out how to so bear with me please

2 comments

0

Why are you allocating UIS, then using a deprecated input-detection method...?

0

Also, StarterGui is a replication container. The GUIs are shifted into individual folders in each Client called "PlayerGui". You can reference this through the LocalPlayer Object.

1 answer

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(K, playerIsChatting)
	
if K.KeyCode == Enum.KeyCode.E then
if not playerIsChatting then 
	
	Profile.Visible = false -- hide gui
        Friends.Visible = false -- hide gui

        print("Menu GUI Deactivated")

		end
	end
end)

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