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

How To Create an Open/Close GUI?

I am trying to create a gamepass shop but this code is not working... can someone please help?

local function Visible()
	if game.StarterGui.Gamepasses.Shop.Visible = false
	then
		game.StarterGui.Gamepasses.Shop.Visible = true
	else
		game.StarterGui.Gamepasses.Shop.Visible = false
	end
end

game.StarterGui.Gamepasses.FrameA.ImageButton.MouseButton1Click:Connect(Visible)

2 comments

0

Oh and on the end it should be (Visible)

0

There are YT tutorials all about GUIs they are helpful

3 answers

✓ Accepted answer

The active user-interface doesn't reside under StarterGui. This Service acts as a container for the general UI assets that are to be replicated to each individual Client (Player). For an easier explanation, It is akin to the way StarterGear behaves.

In order to individually modify local GUIs, you must reference the PlayerGui container, within the LocalPlayer.


--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local Player = Players.LocalPlayer


local PlayerGUI = Player:WaitForChild("PlayerGui")

local GamepassesGUI = PlayerGUI:WaitForChild("Gamepasses")

local ShopFrame = GamepassesGUI:WaitForChild("Shop")

local ButtonContainer = GamepassesGUI:WaitForChild("FrameA")
local OpenButton = ButtonContainer:WaitForChild("ImageButton")



--###----------[[FUNCTIONS]]----------###--
local function OnButtonClicked()
	ShopFrame.Visible = (not ShopFrame.Visible)
	--// Simplifies your conditional scope.
end



--###----------[[SETUP]]----------###--
OpenButton.MouseButton1Click:Connect(OnButtonClicked)

Using not is better in this scenario, it reduces the amount of time it takes to write it.

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:FindFirstChildWhichIsA("PlayerGui") -- PlayerGui, not StarterGui

local Gamepasses = PlayerGui:WaitForChild("Gamepasses")
local FrameA = Gamepasses:WaitForChild("FrameA")
local ImageButton = FrameA:WaitForChild("ImageButton")

ImageButton.MouseButton1Click:Connect(function()
	Gamepasses.Shop.Visible = not Gamepasses.Shop.Visible
end)

heres how starter gui works, whatever you put inside of the starter gui will be inside of the client, becuase of that, it is no longer inside of the folder "StarterGui." Instead, it is inside of the folder inside of the "Players" service. The Folder is called "PlayerGui." Anyways, if you put a script inside of the button, it will also get copied into the "PlayerGui" Folder

example of "PlayerGui" :

https://drive.google.com/file/d/1sFoO6r4G_i_wjQALyQi3f1FUQAbaxY8K/view?usp=sharing

what your ui should look like:

https://drive.google.com/file/d/1ejqMceShvdoZ0O0n9uQ1GSW1ypOTyne8/view?usp=sharing

(paste the link into your browser)

put the script inside of the button

local button = script.Parent
local frame = script.Parent.Parent.Frame
button.MouseButton1Click:Connect(function()
	if frame.Visible == false then
		frame.Visible = true
	else
		frame.Visible = false
	end
end)

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