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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago
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!

0
There was a parsing error with the last end). Do i need to add another end before that? Juansirdudefam 24 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
Log in to vote
0
Answered by
ghxstlvty 133
4 years ago

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.

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'. Juansirdudefam 24 — 4y
0
Try parenting the variable differently. ghxstlvty 133 — 4y

Answer this question