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

How do I use this script to close a gui button?

So far I have this script

local gui = script.Gui

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

I have gotten the gui to open on a click but now I can't get it to close when I use this script. What am I doing wrong?

3 answers

local gui = script.Gui

script.Parent.MouseButton1Click:Connect(function()
if gui.Visible == true then
gui.Visible = false
else
gui.Visible = true
end)

Please accept my answer if I helped!

1 comment

0

There was a parsing error with the last end). Do i need to add another end before that?

ok I'm just gonna say you have many errors but the smart thing is to do is to make the script a child of the gui so it should be like this

local gui = script.Parent
gui.MouseButton1Click:Connect(function()


gui.Enabled = false
end)

or try doing this its more complicated but it will do the function in the whole gui again make the script a child of the gui

local guitable = script.Parent:GetChildren()
local gui = script.Parent
gui.MouseButton1Click:Connect(function()
for i, v in pairs(guitable) do

v.Visible = false



end

Try using this code: (I wrote this code on scripting helpers, please tell me if there is any errors.)

local gui = script.Parent
script.Parent.MouseButton1Down:Connect(Function()

gui.Enabled = false
end)

If there are any errors let me know.

2 comments

0

There is an error regarding the gui.Enabled = false. Under the gui part of it there is a red line that says "expected ) to close ( at line 2. Got 'gui'.

0

Try parenting the variable differently.

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