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

How Do i make the Open/Close Gui with the TextButton?

I've been trying for over a week to make an open and close button for Frame, ScrollingFrame, and TextLabel to make a store on my map if anyone knows please tell me

i trying this code but dont work on the TextButton with the LocalSript

local Button = script.Parent
Frame = script.Parent.Parent.Menu

function onClick()
if Frame.Visible == false then
Frame.Visible = true
elseif Frame.Visible == true then
Frame.Visible = false
end
end

Button.MouseButton1Click:connect(onClick)

5 comments

0

Are there any errors in the output? Also, indent your code; this can do it for you: https://www.roblox.com/library/592898457/Script-indenter

0

Use :Connect() and im pretty sure functions need "end)

0

Use :Connect() and im pretty sure functions need "end)"

0

Btw, use :Connect instead of :connect, it's deprecated.

0

That script should work. I'd recommend making sure your Button and Frame variables are defined correctly.

1 answer

Use WaitForChild on Objects that may need time to load before the script does. Remember to also use local variables, unless you actually need it to be global, which you don't here. If this doesn't work, your Parents are wrong, so double check them.

  • Edited for question in comment
local Button = script.Parent
local Shop = script.Parent.Parent:WaitForChild("Shop")
local Frame = Shop:WaitForChild("Menu")
-- Keep it local and use WaitForChild() 

function onClick()
	Frame.Visible = not Frame.Visible
	-- You only need one line, it will switch based on its Visible property
end

Button.MouseButton1Down:Connect(onClick)

20 comments

0

Please provide an explanation.

0

Azarth I'm going to try this but I have a question "I have to change the local part * Frame = script.Parent.Parent: WaitForChild (" Menu ") * by * local Frame = script.Parent.Parent.Shop:WaitForChild (" Menu")*

0

because the Name of the Frame is "Shop" (that's the shop frame)

0

Edited. Check your output if it doesn't work and wait a little while, because you might get an error from WaitForChild() if your Parents are wrong.  

0

ok im going to try now

0

it's not working but i am going to do something just to see if its going to work

0

oh... its says on output "Shop is not an valid member of frame"

0

Your parenting is wrong. What does your hierarchy look like?

0

the Local Script hierarchy or the Frame hierarchy?

0

sorry if this question is stupid its because i just have 12 years and i am making a game

0

According to your code, everything should be formatted as follows: https://imgur.com/a/yld5pKZ

0

it's already this way ThetaCat

0

This is getting too long for a simple problem, I'm going to make you a model.

0

shop it's inside of Menu

0

Send a picture of where everything is placed so we can better assist you.

0

im going to take a picture and send on my twitter wait a sec ok?

0

im going to try something

0

oh sorry guys i need to go to bed now tomorrow i am going to try

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