Reversing Hide Gui by clicking it again

I have a Hide Gui button and don’t know how to reverse the effects by clicking the button again. Is there a simple line of code I can add to achieve this? Here is the script I currently have:

local GUI = script.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	GUI.MyGui.MainFrame1.Visible = false
	GUI.SpectateGui.SpectateButton.Spectate.Visible = false
end)

Also, just a quick question about scripting, what is the difference between using script.Parent.Parent and game.StarterGui.ScreenGui

Sorry for the inconvenience,

Many thanks!

:smiley:

1 Like

All of the children of StarterGui are cloned into a player’s PlayerGui, so changing something in StarterGui will not change it for any players. script.Parent.Parent, on the other hand, references the PlayerGui, so values can be changed while the game is running.

1 Like

Regarding this, script.Parent.Parent means navigation to instance starting from the location of script. And game.StarterGui.ScreenGui is wrong since each time player respawn(unless gui reset on respawn is set to off) and joins the game for the first time(Unless auto loading of a character is set off too) it will clone every instance of StarterGui service to PlayerGui. I think you meant to type game.Players.LocalPlayer.PlayerGui[Further location to your GUI starting from StarterGui]. They are basically the same. Only change would be if you move script to another instance, so it will take effect and won’t point at the same instance you originally intended it to point at. Keep this in mind so you won’t be confused later!

1 Like

There is a very simple solution since the visible property is a bool value :stuck_out_tongue:

script.Parent.MouseButton1Click:Connect(function()
	GUI.MyGui.MainFrame1.Visible = not(GUI.MyGui.MainFrame1.Visible)
	GUI.SpectateGui.SpectateButton.Spectate.Visible = not(GUI.SpectateGui.SpectateButton.Spectate.Visible)
end)

Regarding script.Parent.Parent is the better method as starter gui is a gui storage.

Player Joins, All GUIs cloned from STARTER GUI to PLAYER GUI, scripts work

3 Likes

Thanks for the reply, it works!

1 Like

Thanks for the information!

:smiley:

1 Like

Thanks for the information!

:smile:

1 Like