I am trying to make a shop for a simplistic banking system. Every time I test it (by creating a test server) the shop won't open due to this error:
"Shop is not a valid member of ScreenGui"
Script 'Players.Player1.PlayerGui.Cash.ShopButton.LocalScript', Line 2
Above ^ is where the code is found inside the local player, but can also be found through
game.StarterGui.Cash.ShopButton.LocalScript
However, it is a child of the ScreenGui, there is no possible way that it is not. Why does it do that?
The code in the Script of which the error occurred in;
ShopB = script.Parent Shop = game.Players.LocalPlayer.PlayerGui.Cash.Shop ShopB.MouseButton1Click:connect(function() if Shop.Visible == false then Shop.Visible = true ShopB.Parent.BankFrame.Visible = false else Shop.Visible = false if ShopB.Parent.OpenBank.Text == "Close Bank" then ShopB.Parent.BankFrame.Visible = true end end end)
Keep in mind: The "Shop" is a Frame. The ScreenGui is named "Cash"
Thanks for the help!
Often times, the script loads before the actual instances you're trying to retrieve have loaded. To prevent this, use the WaitForChild
function to define them!
Also, since the Visible
property of a gui returns a bool, then you can use the not
operator on it to 'toggle' the bool. This way false becomes true and true becomes false. So just do gui.Visible = not gui,Visible
(:
ShopB = script.Parent Shop = game.Players.LocalPlayer.PlayerGui.Cash:WaitForChild('Shop') ShopB.MouseButton1Click:connect(function() ShopB.Visible = not ShopB.Visible Shop.Visible = not Shop.Visible end)