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

Are there any errors in my opening and closing GUI scripts?

I made this local script to open the GUI

script.Parent.MouseButton1Click:connect(function()
	game.StarterGui.Shop.MainFrame.Visible = true
end)

I made this local script to close the GUI

script.Parent.MouseButton1Click:connect(function()
	game.StarterGui.Shop.MainFrame.Visible = false
end) 

Are there any errors in them that make them not work?

2 answers

✓ Accepted answer

Your issue is that you are editing a GUI in the StarterGui. That is not the GUI in use by the current player. Here is a better alternative to your code.

Please note I have used a recursive FindFirstChild because I do not know the structure of your GUI tree.

To open and close the GUI (same script does both)

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

script.Parent.MouseButton1Click:connect(function()
	local shop = playerGui:FindFirstChild("Shop", true)
	shop.MainFrame.Visible = not shop.MainFrame.Visible
end)

You are looking inside the StarterGui, which is just where all the guis are stored. When a player joins the game, all guis in StarterGui are replicated into the player's individual PlayerGui, so that they are unique to each player. So to fix this, you can try replacing the StarterGui with the local player's PlayerGui:

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.PlayerGui.Shop.MainFrame.Visible = true
end)
script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.PlayerGui.Shop.MainFrame.Visible = false
end)

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