I have two GUI's that are opened by a button each at the top of the screen, but I want to make it so that if someone tries to open the second GUI with the first open, it will close the first one before opening the second one.
0
votes
3 Answers
1
votes
You can do something like:
local frames = {
[buttonA] = frameA;
[buttonB] = frameB;
}
for button,frame in pairs(frames) do
button.MouseButton1Click:connect(function()
if frame.Visible then
-- If we try to reopen the current frame, close it
frame.Visible = false
return
end
-- Close all frames and make ours visible
for k,v in pairs(frames) do
-- 'v == frame' is true if it's our frame
v.Visible = v == frame
end
end)
end
You should also check out the ROBLOX Wiki. It has some nice tutorials for Lua and stuff like opening/closing GUIs.
0
votes
100% WORKS To make an opening and closing gui...Put this script: FIRSTGUINAME is your first gui, rename it and SECONDGUINAME is your second gui name so...
FIRSTGUINAME = script.Parent -- very important classifying info SECONDGUINAME = script.Parent.Parent.Parent:WaitForChild(YOUR SECOND GUI)
FIRSTGUINAME.MouseButton1Click:connect(function() SECONDGUINAME.Visible = not Visible
Thats all, now just copy paste this and your set
0
votes
If you want to close a GUI if another one is open you can try this code:
GUI1 = (insert)
GUI2 = (insert)
GUI.MouseButton1Click:connect(function()
if GUI1.Visible == false then
if GUI2.Visible == true then
GUI2.Visible = false
GUI1.Visible = true
else
GUI.Visible = true
end
else
GUI1.Visible = false
end
If you are into the fancy stuff with the tweens, you might have to do that research yourself.