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

How to make a menu box appear and disappear?

Asked by 10 years ago

Alright, so basically I'm working on my newest game and I've come across some issues. The shops in the game are made of surface GUI's. I have it so when you click on "Purchase Credits" a list comes down, but I don't know how to make the list disappear.

local Button = script.Parent
local Small = script.Parent.Parent.Parent.Credits.Small
local Big = script.Parent.Parent.Parent.Credits.Big

local Opened = false

function onClickToOpen() 
    Opened = true

    if (Opened == true) then
        wait(0.5)
        Small.Visible = true
        wait(0.5)
        Big.Visible = true
    else
        wait(0.5)
        Big.Visible = false
        wait(0.5)
        Small.Visible = false
    end
end

function onClickToClose()
    Opened = false
end

if Opened == false and Button.MouseButton1Down:connect(onClickToOpen)then
     wait(0)
end

if Opened == true and Button.MouseButton1Down:connect(onClickToClose)then
    wait(0)
end

If you could help me out that'd be greatly appreciated!

1 answer

Log in to vote
1
Answered by
SanityMan 239 Moderation Voter
10 years ago

(Explanation after example)

--Define variables
local small = script.Parent.Parent.Parent.Credits.Small
local big = script.Parent.Parent.Parent.Credits.Big
local opened = false

function openList() --your function
    if opened == false then --if it is closed when clicked
        opened = true --set the toggle to true
        small.Visible = true --make small visible
        wait(.5) --you had the wait in the original so I assume you want it there
        big.Visible = true --make big visible
    else
        opened = false --set the toggle to false
        big.Visible = false --make big invisible
        wait(.5)
        small.Visible = false --make small invisible
end

script.Parent.MouseButton1Down:connect(openList) --assuming that the script's parent is the button, this should connect the clicking to the function

I left notes throughout this example script explaining what certain parts do.

I can tell you that the reason your script did not take out the list was because of how the onClickToClose function only changed the variable Opened. In order to remove the list, you must not only change the variable, but make the certain GUI parts invisible. This can all be done in one function, which in this example is triggered every time the button is clicked. You were on the right track, though!

If it doesn't work, try posting the output errors so I can help you fix it :)

I hope this helped you!

0
Thank you very much, it helped me a ton! I owe you one! (: frogfriend99 10 — 10y
0
No problem! SanityMan 239 — 9y
Ad

Answer this question