Gui script suddenly broken

I was playing around in studio today working on Gui for a silly little game I’m working on. After finishing the scripts to open and close all the frames, I saved my progress and opened my browser while studio was running in the background because I needed to look at a Dev Hub example for something else I was doing. Now everytime I test it tells me “Dances (name of a screen gui) is not a valid member of PlayerGui” and errors on line 3 so the rest of my code doesn’t work.

Here’s my StarterGui:
Screenshot (4)

And here’s my output: (ignore the weird prints and names please, this is a goofy game to test scripts I might use in my serious project)

Here’s the spot where the error is happening:

-- always visible
local menuButton = script.Parent.Menu.MenuButton
local dancesButton = script.Parent.Dances.DancesButton --The code errors here and stops running

I use Dances in other parts of the script as well.

Is this a bug or did I mess something up that I am unaware of?

Try adding a :WaitForChild() call to those variables, like so:

local menuButton = script.Parent:WaitForChild("Menu"):WaitForChild("MenuButton")
local dancesButton = script.Parent:WaitForChild("Dances"):WaitForChild("DancesButton")

I would guess your script is running before the GUI is made.

2 Likes

That fixed it, thank you!

(30 chars)

1 Like