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 get my open and close gui script to work?

local ScreenGui Production

function wait
if Visible = true
	then wait(5)
	then visible = false
end


1 comment

0

My script is in a LocalScript and it wont work i just want it to play then the player spawn in

2 answers

I'd give you a walkthrough of what you did wrong, but it is just about everything.


Lets start with how you should define the gui. The localscript should be placed directly inside of your TextButton/ImageButton. This way, it is easily accessible by using script.Parent.

local ScreenGui = script.Parent

Next, you need to setup your function. The correct syntax to do so is:

function [name] (arguments)

[code]

end

function Click()
end

Now you can manipulate the Visiblity of your Gui.

function Click()
	ScreenGui.Visible = not ScreenGui.Visible
end

And finally, you need to tie your function to an event. Events in roblox are "listeners" that will fire whenever a specified action occurs. You tie functions to Events in order to make them, well, functional :)

Full product:

local ScreenGui = script.Parent

function Click()
	ScreenGui.Visible = not ScreenGui.Visible
end

--MouseButton1Click is the event that handles clicking for UI ButtonObjects
script.Parent.MouseButton1Click:Connect(Click)
  1. Add a script into Button Or ImageButton then do this
bin = script.Parent
function Click()
	script.Parent.Parent.(NameOfTheGui).Frame.Visible = true

end

bin.MouseButton1Click:connect(Click)

2.Add another script into button or imageButton And the Button's parent should be the opened GUI then Write this

bin = script.Parent
function Click()
	script.Parent.Visible = false

end

bin.MouseButton1Click:connect(Click)

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