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

GUI not closing on button press. What do I do to fix this?

My shop GUI does not want to close. I am using a local script connected to the textbutton that is supposed to be used to close the GUI but the GUI just does not go away after it appears.

I cant seem to put a snip of the code but I'll type it out below.

game.StarterGui.ScreenGui.Frame.TextButton.MouseButton1Click:connect(function()
	script.Parent.Parent.Visible = false
end)

I don't see why this isn't working but the GUI just stays there after I press the button.

2 answers

I can already see a problem from 3 lines. You can't access the GUI with your simple code. You need to have a LocalScript inside of the TextButton. Inside of that very same script, you'll need to type this code:

script.Parent.MouseButton1Click:Connect(function()
        script.Parent.Parent.Visible = false
end)

3 comments

0

The localscript can be anywhere in the ScreenGui though

0

Basically, yes. Using a LocalScript inside of ScreenGui to use the button, is accepted. Because when you try to use the button from "game.StarterGUI" just won't work. The LocalScript is already inside of the needed component.

0

I'm new to Lua lol as you can see. Thnaks guys for the help!

Instead of using game.StarterGui, use script.Parent until you reach the screengui to refer to the TextButton.

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