Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my open/close gui work? I think it has something to do with FE.

So, basically I was busy making some GUIs today, and I was thinking about making a shop, so I added a TextButton on the right, that said 'Shop' when you clicked it, it was supposed to open a frame with contents in it, along with a TextButton at the top right of that frame 'X'. Here is the script:

NOTE: This is a LocalScript, inside of the open TextButton.

local open = script.Parent
local shop = script.Parent.Parent.Frame
local close = script.Parent.Parent.Frame.Close

open.MouseButton1Click:Connect(function(open)

shop.Visible = true

end

close.MouseButton1Click:Connect(function(close)

shop.Visible = false

end

Any idea why it doesn't work?

3 comments

0

Sorry that I couldn't format it right.

0

Can you format it??? its not that hard

0

I'm having the same problem.

2 answers

✓ Accepted answer

NOTE - PLEASE USE CODE BLOCKS!

An open/Close GUI doesn't need two "functions" to run it! Many of my open/close UI's for things, without tween service, only requires one function to run. I have rewrote your code in order to make the open/close UI function below! Reminder as posted in comments by Peyton, instead of using DIFFERENT open/close buttons, maybe simple this down to one! This code will work with just ONE button! If this fails, please comment! If functioning, please accept!

local frame = script.Parent.Parent.Frame

script.Parent.MouseButton1Click:Connect(function()
	frame.visible = not frame.Visible -- Easy way to having a frame open/close without adding extra lines
end)

-- Post comments if this doesn't work!

5 comments

0

He has a Close button which is separate from the frame...

0

^It should just be one button for the function. As, more than one button causes screen overload. As well, it will be more useful with just the one button as well as handy for players.

0

But he wants to use his x button its his preference

0

Placing that code inside an x button will also close it if the frame is still the same name.

1

Thank you so much, I realized that the 'X' button was just extra, you are the best, once again, thank you so much!

When you are writing LocalScripts, especially GUI, you need to use WaitForChild when referencing GUI elements. That is because they may not replicate, before the script is run:

local open = script.Parent -- script is descendant, no WaitForChild() here
local shop = script.Parent.Parent:WaitForChild("Frame") --important!
local close = script.Parent.Parent.Frame.Close --no need here, as "Frame" Parent is already loaded, and close is descendant

open.MouseButton1Click:Connect(function() -- I do not think MouseButton1Click passes any arguments

shop.Visible = true

end)  --don't forget closing bracket

close.MouseButton1Click:Connect(function() -- I do not think MouseButton1Click passes any arguments

shop.Visible = false

end) --don't forget closing bracket

This discussion is preserved as it was. New answers, comments, and votes are closed.