I have a game, and I have this code for purchasing a gamepass. But.... I got this confusing error when I try it. "11:59:59.999 - Players.Player1.PlayerGui.AdvertisementGUI.CoilGears1.LocalScript:6: attempt to index field 'Parent' (a nil value)". My code is:
if game.Players.LocalPlayer.userId > 1 then
if game.MarketplaceService:PlayerOwnsAsset(game.Players.LocalPlayer, 578580632) then
script.Parent:Destroy()
end
end
script.Parent.MouseButton1Click:connect(function()
game.MarketplaceService:PromptPurchase(game.Players.LocalPlayer, 578580632)
end)
Now, look at line 6.
script.Parent.MouseButton1Click --:connect(function() --I disconnected the code so the syntax isn't confused
Isn't "script" supposed to mean the script? Then why it shows that error? Also btw its a local script.

1 comment
Oh, thanks! I know how to fix my code now! (Basically by swaping the code order, and makes it so that the event disconnects before destroying it)