Is there a way to make a gui close automatically if another one is opened? I'm creating a menu screen and currently if a gui is open and you press another button, it will just layer over the top of the previously opened gui and you have to close it manually. I tried coding it myself but it would just bug out and make you click multiple times in order for the guis to transition. Here is my code:
local button1 = script.Parent.Parent.Parent.Parent.Photos -- Change frame names to applicable ones
local button2 = script.Parent.Parent.Parent.Parent.Teleporters
local button3 = script.Parent.Parent.Parent.Parent.Updates
-- Script --
local Button = script.Parent
local MainFrame = script.Parent.Parent.Parent.Parent.Credits
MainFrame:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Sine", .1, false)
Button.MouseButton1Click:Connect(function()
if MainFrame.Visible == false then
if button1.Visible or button2.Visible or button3.Visible == true then
button1:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Back", 1, false)
button2:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Back", 1, false)
button3:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Back", 1, false)
wait(1)
end
MainFrame.Visible = true
MainFrame:TweenPosition(UDim2.new(0.374, 0, 0, 0), "Out", "Back", 1, false)
else
MainFrame:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Back", 1, false)
wait(1)
MainFrame.Visible = false
end
end)
** You are now Level 5! **