Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Osamiku 12
4 years ago
Edited 4 years ago

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

0
Why are you allocating UIS, then using a deprecated input-detection method...? Ziffixture 6913 — 4y
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. Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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)
Ad

Answer this question