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

am trying make the Open And Close with just one button?

Okay so I am trying make a open and gui script. This is what I have and it only works in studio but not in the actual game, I don't know what I could've did wrong :/. But can I also use this as Image Button instead?

local Button = script.Parent
Frame = script.Parent.Parent.Parent.BuyCash

function onClick()
if Frame.Visible == false then
Frame.Visible = true
elseif Frame.Visible == true then
Frame.Visible = false
end
end

Button.MouseButton1Click:connect(onClick)

4 comments

0

Or can I make this into a simple way of coding it?

0

Not sure what you did wrong, but you can rewrite this so it's more succinct: "Frame.Visible = not Frame.Visible"

0

ScrewDeath is correct. Also switch to Connect since connect is deprecated

0

Are you error checking in-game? It could be as simple as using WaitForChild in case your "BuyCash" frame doesn't exist during the execution of the script.

2 answers

It seems to work fine. Try removing the "elseif" like the other reply said. However, for simplicity, I've edited the code a bit so that it looks cleaner & easier to manage:

local Button = script.Parent
Frame = script.Parent.Parent.Parent.BuyCash

function onClick()
	Frame.Visible = not Frame.Visible
end

Button.MouseButton1Click:connect(onClick)

Probably the elseif is messing things up as normal.

Try this:

local Button = script.Parent
Frame = script.Parent.Parent.Parent.BuyCash

function onClick()
if Frame.Visible == false then
Frame.Visible = true
else 
Frame.Visible = false
end
end

Button.MouseButton1Click:connect(onClick)

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