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?
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!
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