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

Open / Close button script is not working when clicked?

Asked by 5 years ago

making a text button open and close a GUI on click and it's not working. Here is the script

01local Button = script.Parent
02local stat = game.StarterGui.Menu.Frame
03 
04Button.MouseButton1Click:Connect(function()
05    if stat.Visible == false then
06        stat.Visible = true
07    else
08        stat.Visible = false
09    end
10end)

3 answers

Log in to vote
1
Answered by
TopBagon 109
5 years ago

the answer above ain't gonna work cause the problem is in your "stat" variable, instead of using game.StarterGui... and so on try going like script.Parent.Parent... so here's an example:

01local Button = script.Parent
02local stat = script.Parent.Parent:WaitForChild("Frame")
03 
04Button.MouseButton1Click:Connect(function()
05    if stat.Visible == false then
06        stat.Visible = true
07    else
08        stat.Visible = false
09    end
10end)

make sure to correct the frame position if it's incorrect.

Now there's nothing wrong with this script but if you want you can get shorter script by using what person above suggested, in this case it'll look similar to this:

1local Button = script.Parent
2local stat = script.Parent.Parent:WaitForChild("Frame")
3 
4Button.MouseButton1Click:Connect(function()
5    stat.Visible = not stat.Visible
6end)

Good luck, hope this helped.

1
Can't upvote because of my rep, but this answer should work. Since this would be a LocalScript, you can also use game.Players.LocalPlayer.PlayerGui.Menu.Frame hpenney2 53 — 5y
0
Smart. I can upvote you tho xD but I'm just here to help people not to gain reputation and stuff... TopBagon 109 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I see you did a different way, I do not know how to fix it, but I know a different way to do it, someone told me this before.

1Button.MouseButton1Click:Connect(function()
2    stat.Visible = not stat.Visible
3end)

Hope it helps. :3

0
thanks a lot i will give it a try later and accept the answer if it works DraconianSG 58 — 5y
Log in to vote
0
Answered by 5 years ago

Nope, not quite, but you can do this: Add 2 TextButtons or ImageButtons (your choice whether you want it as image or text). Make them in the same position as the other (and size). Name the first one "Button1". Name the Second one "Button2". Insert your frame/scrollingframe/textlabel/whatever. Put this all into a ScreenGui. (insert the ScreenGui into StarterGui (unless another reason)) Then insert a LocalScript into the ScreenGui and do the following:

01local Button1 = script.Parent.Button1
02local Button2 = script.Parent.Button2
03local Frame = script.Parent.Frame
04 
05Button1.MouseButton1Click:connect(function()
06     Frame.Visible = true
07end)
08 
09Button2.MouseButton1Click:connect(function()
10     Frame.Visible = false
11end)

Last but not least, make the different text on each button!

Answer this question