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

Error that seems to be "Incorrect"?

Asked by 8 years ago

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!

1
Use WaitForChild to wait for the Shop Frame to become available. http://wiki.roblox.com/index.php?title=API:Class/Instance/WaitForChild Spongocardo 1991 — 8y

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)
Ad

Answer this question