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

Script error: "MainFrame is not a valid member of ScreenGui"?

Asked by 4 years ago
#this is the localscript

local MarketplaceService = game:GetService("MarketplaceService")

local MainFrame = script.Parent.MainFrame
local machineGunGamepass = MainFrame.MachinegunGamepassFrame.MachineGunGamepass
local OpenShop = MainFrame.Parent.OpenShop

local player = game.Players.LocalPlayer

local MachineGunGamepassID = 8731365

machineGunGamepass.MouseButton1Down:connect (function()
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, machineGunGamepassID)
    end)

        if hasPass then
            print("player already has the gamepass")
        else
            MarketplaceService:PromptGamePassPurchase(player, machineGunGamepassI)
        end
end)

OpenShop.MouseButton1Down:Connect (function()
    MainFrame.Visible = not MainFrame.Visible
end)

#this is the script

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local MachineGunGamepassID = 8731365

game.Players.PlayerAdded:Connect(function(Player)

    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, MachineGunGamepassID)
    end)

    if hasPass then
        print("player has the gamepass")

        local Sword = game.ReplicatedStorage.MachineGun:Clone()
        MachineGun.Parent = player.Backpack
    end
end)

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)

    if purchaseSuccess == true and purchasedPassID == MachinegunGamepassID then
        print(player.Name .. " purchased the game pass!")

        local Sword = game.ReplicatedStorage.MachineGun:Clone()
        MachineGun.Parent = player.Backpack
    end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

hi, my code is for a shop i made but when i play the shop wont open and the "output tab tells me that "MainFrame is not a valid member of ScreenGui" Please help

0
is the actual MainFrame capitalized like shown in the script? karesiku 72 — 4y
0
also try replacing mainframe's variable with local MainFrame = script.Parent:WaitForChild("MainFrame") karesiku 72 — 4y
0
Like @karesiku said, you should do like that. Because, maybe the MainFrame is not loaded so the script can't find it. Block_manvn 395 — 4y

Answer this question