I'm testing out a gamepass that gives the player a potato when they buy it.
Currently, it's not working because it says player is nil at line 13.
How can I fix this?
local passId = 264705769 -- change this to your game pass ID.
local potato = game.Lighting:WaitForChild("Potato"):Clone()
function isAuthenticated(player) -- checks to see if the player owns your pass
return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end
game.Players.PlayerAdded:connect(function(plr)
if isAuthenticated(plr) then
local player = game.Players.LocalPlayer
print(plr.Name .. " has bought the game pass with id " .. passId)
potato.Parent = player.Backpack
potato.Parent = player.StarterGear
end
end)

1 comment
Why make a variable for the player? you could just say "potato.Parent = plr.Backpack". That's what was passed in the PlayerAdded event.