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

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

Asked by 6 years ago

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)

0
Or can I make this into a simple way of coding it? NeriodKid 6 — 6y
0
Not sure what you did wrong, but you can rewrite this so it's more succinct: "Frame.Visible = not Frame.Visible" ScrewDeath 153 — 6y
0
ScrewDeath is correct. Also switch to Connect since connect is deprecated User#19524 175 — 6y
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. saenae 318 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

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)
Ad
Log in to vote
0
Answered by 6 years ago

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)

Answer this question