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

Why do I get the error "open is not a valid member of ScreenGui" when open is a child of ScreenGui?

Asked by 7 years ago

This is my first time messing with GUIs for quite a while, so I apologize in advance if the solution is something simple. I am currently working on an inventory and shop GUI. Inside of both of the screen GUIs I have a button named open, A scrolling frame and a local script which is the main controller for the GUI. Inside of both scripts I have the following code:

script.Parent.open.MouseButton1Click:connect(function()
    UpdateInventory()
end)

Update inventory being the main function for the GUI (opening, closing etc). Now when I play the game everything works fine and dandy, it opens the GUI and lists objects you can buy or objects currently in your backpack. Now the problem comes when I create a test server or test the game outside of studio. The inventory GUI works quite well, what doesn't work is the shop GUI, even though it shares the same exact script for when the button is pressed. I get an error in the console stating: open is not a valid member of ScreenGui. Even though in the explorer you can clearly see open as a child of the screen GUI. While I was trying to debug this I created a script that prints off the children of the screen GUI, and sure enough, open was listed. Now I have a few questions if anyone wants to answer them. Why is this error happening? Why does the inventory GUI not suffer the same problem? And how should I go about fixing this?

0
Sometimes in a roblox server it can take awhile for things to load. Try adding WaitForChild("open") into the line where it is giving the error in trying to access open, it should work this time, giving the GUI element time to load dragonkeeper467 453 — 7y
0
I'd suggest using a repeat loop instead as the WaitForChild function can go on for a while even when then child has been found which can lead to lag/memory hogging. Meltdown81 309 — 7y
0
The wait for child worked well, thankyou. How would I setup the repeat loop? TheEnderShot 14 — 7y
1
@Meltdown Nonsense. It's actually the other way around. Link150 1355 — 7y
0
If you want to prevent the :WaitForChild() waiting forever, add a second argument that is a number, like :WaitForChild("object", 5) to wait for that for 5 seconds, or whatever number you put there. Just make sure you handle the case that it returns nil if it can't find it in the time limit. GoldenPhysics 474 — 7y

Answer this question