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

Gui not becoming visible when button is pressed?

Hi, Im trying to make a screen button where if you press it, the current gui becomes invisible and a different one becomes visible. Here is my script. The "mainMenu" gui becomes invisible, but the "WorldSelector" does not become visible.

Button = script.Parent
mainMenu = script.Parent.Parent
WorldSelector = game.StarterGui.WorldSelector.Frame
Button.MouseButton1Click:Connect(function()
	WorldSelector.Visible = true
	mainMenu.Visible = false
	print("Button Pressed")
end)

2 comments

0

Maybe you forgot the name of it, or mentioned it in a variable incorrectly, check the world selector in the explorer again

0

Make sure its a local script, and change WorldSelector = game.Players.LocalPlayer.PlayerGui.WorldSelector.Frame

1 answer

✓ Accepted answer

You're changing the visibility of the WorldSelector GUI that's in StarterGui, not in the LocalPlayer's PlayerGui.

local player = game.Players.LocalPlayer

local button = script.Parent
local mainMenu = button.Parent
local worldSelector = player.PlayerGui.WorldSelector.Frame

button.MouseButton1Click:Connect(function()
	worldSelector.Visible = true
	mainMenu.Visible = false
	print("Button Pressed")
end)

Changing the visibility of the WorldSelector frame that's in StarterGui won't do anything to the GUI that's in the player's PlayerGui, because StarterGui is just where you put GUIs that you want to be cloned into each player's PlayerGui. The GUIs that each player sees is in their own PlayerGui.

2 comments

0

Also, be more consistent when it comes to naming your variables(you named one variable mainMenu and another WorldSelector), and localize them (put the word "local" before the variable name) when you're defining them. It makes reading the script just a little bit faster, and you should get into the habit of doing it.

1

Thank you so much

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