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

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
MrNicNac 855 Moderation Voter
6 years ago

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)
Ad
Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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)

Answer this question