#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

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