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

CoinGui isn't a valid member of player gui help?

Asked by 10 years ago

Well there is an error on this script and it says: CoinGui is not a valid member of PlayerGui. Well it is a valid member because I saw it in my player gui while testing. It makes no sense. Here is the script that is causing the problem.

local coins = script.Parent.Parent.CoinGui.Coins

for i, v in pairs(script.Parent.Frame:GetChildren()) do
    if v:IsA("TextButton" or "ImageButton") then
        v.MouseButton1Click:connect(function(player)
            if v.Name == "GrapplingHook" then
                if coins.Value > 349 then
                    coins.Value = coins.Value - 350
                    game.Lighting.GrapplingGun.Parent = player
                end
            end
        end)
    end
end

How is this wrong? Or is Studio just glitching?

1 answer

Log in to vote
0
Answered by 10 years ago

Some items don't load instantly so you need to use WaitForChild to wait until they're available for use.

local coingui = script.Parent.Parent:WaitForChild("CoinGui")
local coins = coingui:WaitForChild("Coins")

for i, v in pairs(script.Parent.Frame:GetChildren()) do
    if v:IsA("TextButton" or "ImageButton") then
        v.MouseButton1Click:connect(function(player)
            if v.Name == "GrapplingHook" then
                if coins.Value > 349 then
                    coins.Value = coins.Value - 350
                    game.Lighting.GrapplingGun.Parent = player
                end
            end
        end)
    end
end
Ad

Answer this question