Why isn't my GUI closing?

My GUI isn’t closing, why?

function Click()
	game.Players:WaitForChild("PlayerGui").TicketGUI.Enabled = false
end
script.Parent.MouseButton1Click:Connect(Click)

This is what it gives me:
Infinite yield possible on 'Players:WaitForChild(“PlayerGui”)

Make sure it is loaded in properly, try making it a variable:

local PlayerGui = game.Players:WaitForChild("PlayerGui")

Same problem, isn’t closing, also in the first script i was noticing some output lag

What type of script are you using?

local script, but i’ll try it on a normal script if i need to replace it

Why are you getting PlayerGui on a local script?

idk why, also tried it on a normal script, didn’t work

Where is your script located in the explorer?

omg. Do:

game.Players.LocalPlayer:WaitForChild("PlayerGui").TicketGUI.Enabled = false

This should work. If you have any questions then feel free to ask

1 Like

in the startergui in the ticketgui in a textbutton

is it supposed to be a local script?

yes it is. Local player can ONLY be accessed from a local script

1 Like

You don’t even need to do that in a local script though.

wdym? if you do it in a server script it will return nil. The only time you can get local player from a server script is via remote events but i’m trying to keep it simple

I am saying a easier method would be to put the local script in the GUI and have a variable for the frame.

Please define your objects before you use them. This makes your script much easier to read.

local button = script.Parent
local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local gui = playerGui:WaitForChild("TicketGUI")

function OnClick()
	gui.Enabled = false -- or 'not gui.Enabled' if you the button should toggle
end

button.MouseButton1Click:Connect(OnClick)