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

Gui not becoming visible when button is pressed?

Asked by 3 years ago

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)
0
Maybe you forgot the name of it, or mentioned it in a variable incorrectly, check the world selector in the explorer again Almighted 0 — 3y
0
Make sure its a local script, and change WorldSelector = game.Players.LocalPlayer.PlayerGui.WorldSelector.Frame Brycefitz2008 2 — 3y

1 answer

Log in to vote
0
Answered by
Rinpix 639 Moderation Voter
3 years ago

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.

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. Rinpix 639 — 3y
1
Thank you so much CaptainStevones123 12 — 3y
Ad

Answer this question