Open Gui Script not working

I want to make a Open Gui

I could not find the error in my code, can you help?

I have tried to use the output to help me but it did not help.

So i own a game that has a error. My game is a buggy mess. Most of them i can fix but this one is concerning.

-- local branch = script.Parent --Variable points to ScreenGui & everthing inside/below it.
local open = branch["Open/Close"] --Variable points to the open/close button.
local MainFrame = branch.Frame --Variable points to "Frame".

open.MouseButton1Click:connect(function() --Anonymous function that is wired to the open/close button.
	if script.Parent.Parent.Parent.Frame.Visible == true then 
		 script.Parent.Parent.Parent.Frame.Visible = false 
	if script.Parent.Parent.Parent.Chapters.Visible == false then --If Frame isn't Visible then 
		script.Parent.Parent.Parent.Chapters.Visible = true --frame becomes visible
	end
end		

Please just Tell me the error and i will be happy.

Looks like you’re just missing an end, and a ‘)’ at the bottom line for your event connection.

open.MouseButton1Click:connect(function() --Anonymous function that is wired to the open/close button.
	if script.Parent.Parent.Parent.Frame.Visible == true then 
		 script.Parent.Parent.Parent.Frame.Visible = false 
    end
	if script.Parent.Parent.Parent.Chapters.Visible == false then --If Frame isn't Visible then 
		script.Parent.Parent.Parent.Chapters.Visible = true --frame becomes visible
	end
end)
1 Like

it still does not work

Not an debugging but, you can make the code better by simply doing this:

local open = branch["Open/Close"] --Variable points to the open/close button.
local MainFrame = branch.Frame --Variable points to "Frame".
local Gui = script.Parent.Parent.Parent.Frame

open.MouseButton1Click:Connect(function() --Anonymous function that is wired to the open/close button.
	Gui.Visible = not Gui.Visible
end)

But… I noticed you used connect, which is deprecated, you should use Connect instead.

1 Like

This did work thank you. I worked.

1 Like