Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 5 years ago
Edited 5 years ago

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?

0
Sorry that I couldn't format it right. Cvllapse 30 — 5y
0
Can you format it??? its not that hard Prestory 1395 — 5y
0
I'm having the same problem. sourcandiezz 0 — 5y

2 answers

Log in to vote
0
Answered by
BryanFehr 133
5 years ago
Edited 5 years ago

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!
0
He has a Close button which is separate from the frame... Prestory 1395 — 5y
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. BryanFehr 133 — 5y
0
But he wants to use his x button its his preference Prestory 1395 — 5y
0
Placing that code inside an x button will also close it if the frame is still the same name. BryanFehr 133 — 5y
1
Thank you so much, I realized that the 'X' button was just extra, you are the best, once again, thank you so much! Cvllapse 30 — 5y
Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago
Edited 5 years ago

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

Answer this question