GUIs not enabling via script

I’ve been having this problem for a while now…

So I made a clear baseplate, put two screen guis, add frames to both of em, add a button to the first one that makes its current GUI set the Enabled option to false and the other to true (Having it set to false by default). It doesn’t work. Anything that I’m missing here…?

4 Likes

It’s sort of more complicated how StarterGui works, StarterGui is just a container for all the guis that everyone gets a copy of when they join, you’ll have to make changes to your copy of those guis, and not the container with the originals. You have a folder directly parented to your player called PlayerGui, where your copy of the guis are kept, you’re supposed to make those changes there.

local PlayerGui = game.Players.LocalPlayer.PlayerGui 
local nextGui = PlayerGui.NextScreenGui --**your** version of nextGui 
2 Likes

Had no idea about this. Thanks! All I have to do is, from the PlayerGui, grab the ScreenGui and set the Enabled value to false and then, from the PlayerGui, set the NextScreenGui Enabled value to true, right?

1 Like

I tried that before but it didn’t work for me. Any idea why?

It lands me an error of the GUI’s name not existing as a valid member of PlayerGui… Strange…

Here is the reason why it won’t work as jefelocaso explained earlier.
image

Here is my solution I think. (The localscript would be in startercharacterscripts)

local player = game.Players.LocalPlayer
local nextGui = player.PlayerGui.NextScreenGui
local thisGui = player.PlayerGui.ScreenGui

local button = thisGui.Frame.TextButton

button.MouseButton1Click:Connect(function()
    thisGui.Enabled = false
	nextGui.Enabled = true
end)

image

3 Likes

It worked! But why? Since StarterCharacterScripts is often used for the player’s character often known as the player’s model? It would have made more sense in the StarterPlayerScripts but it didn’t worked there

The issue here may be that the GUI hasn’t loaded at the point when you are accessing gui2. Using WaitForChild() should account for this issue.

local player = game.Players.LocalPlayer
local nextGui = player.PlayerGui:WaitForChild("NextScreenGui")
local thisGui = player.PlayerGui:WaitForChild("ScreenGui")

local button = thisGui.Frame.TextButton

button.MouseButton1Click:Connect(function()
    thisGui.Enabled = false
	nextGui.Enabled = true
end)

Also, as a side note, if you make gui1 (thisGui) a parent of the LocalScript, then you can access the GUI by simply using script.Parent rather than going through the contents of PlayerGui.

4 Likes

This also solves the problem and it doesn’t need to move the local script to the StartedCharacterFolder. Amazing!

Using both @rapmilo and @ColdCrazyGoku’s solutions works! In case this thread goes for longer, here are the posts!

rapmilo's solution
ColdCrazyGoku's solution

Thanks to everyone! And please keep commenting more ways to approach this problem as it will help others in the future!

1 Like