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.
You destroyed the script's parent in line 3, then tried to access it's parent (now nil) in line 6, which errors of course. I didn't know scripts could run with no parent though... well you probably want to delete the script as well with script:Destroy().