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

local Button = script.Parent
local stat = game.StarterGui.Menu.Frame

Button.MouseButton1Click:Connect(function()
    if stat.Visible == false then
        stat.Visible = true
    else
        stat.Visible = false
    end
end)

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:

local Button = script.Parent
local stat = script.Parent.Parent:WaitForChild("Frame")

Button.MouseButton1Click:Connect(function()
    if stat.Visible == false then
        stat.Visible = true
    else
        stat.Visible = false
    end
end)

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:

local Button = script.Parent
local stat = script.Parent.Parent:WaitForChild("Frame")

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

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.

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

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:

local Button1 = script.Parent.Button1
local Button2 = script.Parent.Button2
local Frame = script.Parent.Frame

Button1.MouseButton1Click:connect(function()
     Frame.Visible = true
end)

Button2.MouseButton1Click:connect(function()
     Frame.Visible = false
end)

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

Answer this question