Why doesn't this script to hide parts of a Gui work?

Does anyone know why this script doesn’t work? It’s supposed to hide some parts of a gui but it’s not working for me. It’s in a local script inside a textbutton.

local frame = script.Parent.Parent.Parent.Parent.adminGui 

    script.Parent.MouseButton1Click:connect(function()
    	frame.AllCues.Visible = false
    	frame.LiftCues2.Visible = false
    	frame.RunwayLed.Visible = false
    	frame.SideLEDCues2.Visible = false
    	frame.SideLEDCues.Visible = false
    	frame.SiderLED.Visible = false
    	frame.VisualDisplay.Visible = false
    	frame.ImageLabel.Visible = false
    end)

Are you getting any errors etc

It would help if you showed the way your GUI is set up in the workspace.
Also if you put some print statements in there for troubleshooting to see what sections of the script actually run that may help.

i think you are using starter gui instead of playergui. research on playergui.
you supposed to do
game.Players.LocalPlayer.PlayerGui.frame.AllCues.Visible = false
i think maybe

That shouldn’t make a difference

It obviously does, StarterGui is for seeing in studio, PlayerGui is what you have to use.

Try using WaitForChild() to find the frame eg:

local frame = localplayer.PlayerGui:WaitForChild('adminGui')

didnt work unfortunately :frowning:

Try this:

local Player = game:GetService("Players").LocalPlayer
adminGui = Player:WaitForChild("PlayerGui"):WaitForChild("adminGui")
script.Parent.MouseButton1Click:Connect(function()
    for i,obj in pairs(adminGui:GetChildren()) do
	    obj.Visible = false
	end
end)

Is there a specific reason you are using two ScreenGuis for the admin. It is usually easier to put the entire admin Gui inside of one screen Gui. That way you wouldnt be required to find another screengui in player gui

1 Like

The code can run way faster than what it’s intended to be for some reason:

In the code here:

local frame = script.Parent.Parent.Parent.Parent.adminGui 

    script.Parent.MouseButton1Click:connect(function()
    	frame.AllCues.Visible = false
    	frame.LiftCues2.Visible = false
    	frame.RunwayLed.Visible = false
    	frame.SideLEDCues2.Visible = false
    	frame.SideLEDCues.Visible = false
    	frame.SiderLED.Visible = false
    	frame.VisualDisplay.Visible = false
    	frame.ImageLabel.Visible = false
    end)

The first line is already assuming: “I’ve already defined my adminGui, so we’re all set here!”
Yeaaaaaaah no. It will error, resulting in: adminGui is not a valid member of PlayerGui as the Gui has not entirely loaded in yet

But if we go ahead and change our hidden Gui to this:

local frame = script.Parent.Parent.Parent.Parent:WaitForChild("adminGui")

    script.Parent.MouseButton1Click:connect(function()
    	frame.AllCues.Visible = false
    	frame.LiftCues2.Visible = false
    	frame.RunwayLed.Visible = false
    	frame.SideLEDCues2.Visible = false
    	frame.SideLEDCues.Visible = false
    	frame.SiderLED.Visible = false
    	frame.VisualDisplay.Visible = false
    	frame.ImageLabel.Visible = false
    end)

If I recall, the WaitForChild() function will yield all its other lines of code until that certain variable is found, then will continue on its code