How to make a destroy gui and get it back

So im making a destroy gui and i want to get it back by a button but when i press the X that closes the gui the button destroys too

3 Likes

Just separate the button, and put the other UI contents to a different Frame, then use Frame.Visible, set it to false or true.

Could you show what you have so far? Like your UI, and script? Is what you’re trying to make a button which opens a Gui, and inside that Gui a button to close it?

Close one: function onClicked()
script.Parent.Parent.Parent:Destroy()
end
script.Parent.MouseButton1Click:connect(onClicked)

Open: local Frame = script.Parent.Parent.Frame

script.Parent.MouseButton1Click:Connect(function()
Frame.Visible = true
end)

explorer

this didnt work it just deleted the frame which also deleted the button

Instead of deleting the Gui, make it invisible with .Enabled for ScreenGui, and .Visible for GuiObjects like a Frame.

You’re still deleting the ScreenGui, not the Frame. Also, why don’t you just use Frame.Visible? And make the names of the two Frames distinct, so that the two Frames can be accessed.

Well I would but this game will have a lot off gui’s and all running in the background could cause lag

That’s not how GUIs work I believe. As long as the UIs are not moving constantly, it should not impact the UI performance too much.

Why would having a lot of ScreenGuis cause lag just by existing? Unless you have thousands of ScreenGuis, this won’t cause any noticable lag.

Ok to one off my scripters I used frame.visible to open/close frames some had moving parts like a picture changer and my scripter said this has around 4GB off useless background tasks

Everybody uses .Visible or .Enabled to open and close Guis. Nobody uses .Parent or :Destroy to do the same thing. So just change the visibility of the frame, or move it offscreen to open/close the gui.

1 Like

How did your programmer hit 4GB of RAM for a picture changer? If there are thousands of high-quality images, yeah, that will really hit performance. If not, you should not worry.

Your programmer might be talking about the entire game’s RAM use instead of just the UI alone.

1 Like

Maybe it is the RAM but the game is like a operating system based game so its all mostly GUI we have a snake game hes working on so maybe thats causing some issues aswell

To my knowledge, any GUI or part that is invisible will not impact the client performance heavily, you can also pause any script/loop in the ui if it has like 20 loops.

1 Like

If it’s an operating system-type game, you should try separating pieces of your UI to different ScreenGui’s (one for the taskbar, one for windows, one for the desktop, etc.)

On top of what @GuySalami said, never use too many unnecessary loops in your code.

1 Like

If you destroy a Gui, it can’t be retrieved. So you would instead just set the Parent to nil. But I feel like it would be the same if you were just to make it invisible, so I don’t get why you haven’t done this yet.

1 Like

Yes, split up the gui, that is why there is a gui class to support the frames with.

1 Like

We have done stuff like that. But I’m not the best coder either I barely understand stuff but the pictures are looped through a code.

we also have looped texts for instance it would say Hi
then Bye
and repeat that forever