This was the most unholy script I have ever seen.
Fixed Indents - NOT SOLUTION
MenuOpenButton.MouseButton1Click:Connect(function()
local MENUs = game.ReplicatedStorage:FindFirstChild("MENUs")
local BUILD = MENUs.BUILDGui
local CODE = MENUs.CodeGui
local GAMES = MENUs.GAMESTELEPORTGui
local INVENTORY = MENUs.INVENTORYGui
local MAGIMON = MENUs.MagiMonStatsGui
local QUEST = MENUs.QuestLog
local SHOP = MENUs.SHOPGui
local TELEPORT = MENUs.SURFACETeleport
local TUTORIAL = MENUs.TUTORIAL
local BuildBtn = MenuFrame.BuildOpenButton
local BuildOpen = MenuFrame.BuildOpenButton.Open
local CodeBtn = MenuFrame.CodeOpenButton
local CodeOpen = MenuFrame.CodeOpenButton.Open
local GamesBtn = MenuFrame.GamesOpenButton
local GamesOpen = MenuFrame.GamesOpenButton.Open
local InvBtn = MenuFrame.InventoryOpenButton
local InvOpen = MenuFrame.InventoryOpenButton.Open
local MagiBtn = MenuFrame.MagimonOpenButton
local MagiOpen = MenuFrame.MagimonOpenButton.Open
local QuestBtn = MenuFrame.QuestOpenButton
local QuestOpen = MenuFrame.QuestOpenButton.Open
local ShopBtn = MenuFrame.ShopOpenButton
local ShopOpen = MenuFrame.ShopOpenButton.Open
local TeleBtn = MenuFrame.TeleportOpenButton
local TeleOpen = MenuFrame.TeleportOpenButton.Open
local TutBtn = MenuFrame.TutorialOpenButton
local TutOpen = TUTORIAL.Open
if Screen.Open.Value == false then
Screen.Open.Value = true
MenuOpenButton.TextLabel.Text = 'CLOSE MENUS'
MenuFrame:TweenPosition(UDim2.new(0,0,0,0),"Out","Quint",1.5,true)
BuildBtn.MouseButton1Click:Connect(function()
BuildBtn.TextLabel.Text = 'CLOSE BUILD'
if BuildOpen.Value == false then
local gui = BUILD:Clone()
gui.Parent = Plr.PlayerGui
gui.BuildFrame:TweenPosition(UDim2.new(0.294,0,0,0),"Out","Quint",1.5,true)
BuildOpen.Value = true
else
BuildOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('BUILDGui')
BuildBtn.TextLabel.Text = 'BUILD'
GuiToKill:Destroy()
end
end)
CodeBtn.MouseButton1Click:Connect(function()
CodeBtn.TextLabel.Text = 'CLOSE CODES'
if CodeOpen.Value == false then
local gui = CODE:Clone()
gui.Parent = Plr.PlayerGui
gui.CodeFrame:TweenPosition(UDim2.new(0.5, -200, 0.5, -150),"Out","Quint",1.5,true)
CodeOpen.Value = true
else
CodeOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('CodeGui')
CodeBtn.TextLabel.Text = 'CODES'
GuiToKill:Destroy()
end
end)
GamesBtn.MouseButton1Click:Connect(function()
GamesBtn.TextLabel.Text = 'CLOSE GAMES'
if GamesOpen.Value == false then
local gui = GAMES:Clone()
gui.Parent = Plr.PlayerGui
gui.GamesTeleportFrame:TweenPosition(UDim2.new(0.072, 0,0, 0),"Out","Quint",1.5,true)
GamesOpen.Value = true
else
GamesOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('GAMESTELEPORTGui')
GamesBtn.TextLabel.Text = 'GAMES'
GuiToKill:Destroy()
end
end)
InvBtn.MouseButton1Click:Connect(function()
InvBtn.TextLabel.Text = 'CLOSE INVENTORY'
if InvOpen.Value == false then
local gui = INVENTORY:Clone()
gui.Parent = Plr.PlayerGui
gui.InventoryFrame:TweenPosition(UDim2.new(0.3,0,0.2,0),"Out","Quint",1.5,true)
InvOpen.Value = true
else
InvOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('INVENTORYGui')
InvBtn.TextLabel.Text = 'INVENTORY'
GuiToKill:Destroy()
end
end)
MagiBtn.MouseButton1Click:Connect(function()
MagiBtn.TextLabel.Text = 'CLOSE MagiMon STATS'
if MagiOpen.Value == false then
local gui = MAGIMON:Clone()
gui.Parent = Plr.PlayerGui
gui.Frame:TweenPosition(UDim2.new(0.254,0,0,0),"Out","Quint",1.5,true)
MagiOpen.Value = true
else
MagiOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('MagiMonStatsGui')
MagiBtn.TextLabel.Text = 'MagiMon STATS'
GuiToKill:Destroy()
end
end)
QuestBtn.MouseButton1Click:Connect(function()
QuestBtn.TextLabel.Text = 'CLOSE QUEST LOG'
if QuestOpen.Value == false then
local gui = QUEST:Clone()
gui.Parent = Plr.PlayerGui
gui.SettingsFrame:TweenPosition(UDim2.new(0.136, 0,0.065,0),"Out","Quint",1.5,true)
QuestOpen.Value = true
else
QuestOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('QuestLog')
QuestBtn.TextLabel.Text = 'QUEST LOG'
GuiToKill:Destroy()
end
end)
ShopBtn.MouseButton1Click:Connect(function()
ShopBtn.TextLabel.Text = 'CLOSE SHOP'
if ShopOpen.Value == false then
local gui = SHOP:Clone()
gui.Parent = Plr.PlayerGui
gui.Frame:TweenPosition(UDim2.new(0.3,0,0.2,0),"Out","Quint",1.5,true)
ShopOpen.Value = true
else
ShopOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('SHOPGui')
ShopBtn.TextLabel.Text = 'SHOP'
GuiToKill:Destroy()
end
end)
TeleBtn.MouseButton1Click:Connect(function()
TeleBtn.TextLabel.Text = 'CLOSE TELEPORT'
if TeleOpen.Value == false then
local gui = TELEPORT:Clone()
gui.Parent = Plr.PlayerGui
gui.SettingsFrame:TweenPosition(UDim2.new(0.23, 0,0.065, 0),"Out","Quint",1.5,true)
TeleOpen.Value = true
else
TeleOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('SURFACETeleport')
TeleBtn.TextLabel.Text = 'TELEPORT'
GuiToKill:Destroy()
end
end)
TutBtn.MouseButton1Click:Connect(function()
TutBtn.TextLabel.Text = 'CLOSE TUTORIAL'
if TutOpen.Value == false then
local gui = TUTORIAL:Clone()
gui.Parent = Plr.PlayerGui
gui.HowToWinFrame:TweenPosition(UDim2.new(0.004, 0,0.009, 0),"Out","Quint",1.5,true)
TutOpen.Value = true
else
TutOpen.Value = false
local GuiToKill = Plr.PlayerGui:FindFirstChild('TUTORIAL')
TutBtn.TextLabel.Text = 'TUTORIAL'
GuiToKill:Destroy()
end
end)
-- BELOW IS THE CLOSE MENUS BUTTON ACTIONS
else
if BuildBtn.Open.Value == true then BuildBtn.Open.Value = false BuildBtn.TextLabel.Text = 'BUILD' Plr.PlayerGui:FindFirstChild('BUILDGui'):Destroy() BuildOpen.Value = false end
if CodeBtn.Open.Value == true then CodeBtn.Open.Value = false CodeBtn.TextLabel.Text = 'CODES' Plr.PlayerGui:FindFirstChild('CodeGui'):Destroy() CodeOpen.Value = false end
if GamesBtn.Open.Value == true then GamesBtn.Open.Value = false GamesBtn.TextLabel.Text = 'GAMES' Plr.PlayerGui:FindFirstChild('GAMESTELEPORTGui'):Destroy() GamesOpen.Value = false end
if InvBtn.Open.Value == true then InvBtn.Open.Value = false InvBtn.TextLabel.Text = 'INVENTORY' Plr.PlayerGui:FindFirstChild('INVENTORYGui'):Destroy() InvOpen.Value = false end
if MagiBtn.Open.Value == true then MagiBtn.Open.Value = false MagiBtn.TextLabel.Text = 'MagiMon STATS' Plr.PlayerGui:FindFirstChild('MagiMonStatsGui'):Destroy() MagiOpen.Value = false end
if QuestBtn.Open.Value == true then QuestBtn.Open.Value = false QuestBtn.TextLabel.Text = 'QUEST LOG' Plr.PlayerGui:FindFirstChild('QuestLog'):Destroy() QuestOpen.Value = false end
if ShopBtn.Open.Value == true then ShopBtn.Open.Value = false ShopBtn.TextLabel.Text = 'SHOP' Plr.PlayerGui:FindFirstChild('SHOPGui'):Destroy() ShopOpen.Value = false end
if TeleBtn.Open.Value == true then TeleBtn.Open.Value = false TeleBtn.TextLabel.Text = 'TELEPORT' Plr.PlayerGui:FindFirstChild('SURFACETeleport'):Destroy() TeleOpen.Value = false end
if TutBtn.Open.Value == true then TutBtn.Open.Value = false TutBtn.TextLabel.Text = 'TUTORIAL' Plr.PlayerGui:FindFirstChild('TUTORIAL'):Destroy() TutOpen.Value = false end
MenuScript:Destroy()
MenuScript = ScriptBackup:Clone()
MenuScript.Parent = Screen
Screen.Open.Value = false
MenuOpenButton.TextLabel.Text = 'MENUS'
MenuFrame:TweenPosition(UDim2.new(-1, 0,0, 0),"Out","Quint",1.5,true)
end
end)
You could have declared the variables in advance first. Then do a function for each button. Do not destroy any UI, set their visible to false(they won’t render).
The real question is why would you clone and destroy when you can actually show and hide.