So I'm trying to make a simple GUI in which when you click the button, another GUI will appear, and when you click it again, it disappears. It's work perfectly in Studio but whenever I publish it to Roblox, when I join it via Roblox website, it doesn't work and the error reads Rarities is not a valid member of ScreenGui
I'm still new to scripting but I don't understand what's wrong. Here's my script.
~Note: It's Local
Button = script.Parent.TextButton List = script.Parent.Rarities Open = false Button.MouseButton1Down:connect(function(open) if Open == false then Button.Text = "Close" List.Visible = true Open = true elseif Open == true then Button.Text = "Rarities" List.Visible = false Open = false end end)
This is caused because in studio, the player files load up much faster than in a real server. An easy fix for this would be to use WaitForChild. This pauses the thread until the specified variables exist.
So the code should look something like this:
Button = script.Parent:WaitForChild("TextButton") List = script.Parent:WaitForChild("Rarities") Open = false Button.MouseButton1Down:connect(function(open) if Open == false then Button.Text = "Close" List.Visible = true Open = true elseif Open == true then Button.Text = "Rarities" List.Visible = false Open = false end end)