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

Open / Close button script is not working when clicked?

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

✓ Accepted answer

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.

2 comments

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

0

Smart. I can upvote you tho xD but I'm just here to help people not to gain reputation and stuff...

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

1 comment

0

thanks a lot i will give it a try later and accept the answer if it works

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!

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