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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

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)
0
The localscript can be anywhere in the ScreenGui though virushunter9 943 — 3y
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. 2_MMZ 1059 — 3y
0
I'm new to Lua lol as you can see. Thnaks guys for the help! DaGlizzzzzzyyyy 34 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

Answer this question