local gamepass = game:GetService("GamePassService")
local market = game:GetService("MarketplaceService")
function leftClick()
local player = game.Players.PlayerAdded:Connect(leftClick)
market:PromptGamePassPurchase(player, 1057151)
end
script.Parent.MouseButton1Click:Connect(leftClick)
You are incorrectly getting the player because if this script is being ran on the client the PlayerAdded event wont fire when you join the game because you have already joined the game before it has a chance to be fired. Instead you should use the built in method of getting the player on the client: game:GetService("Players").LocalPlayer.
Here is your code fixed:
local gamepass = game:GetService("GamePassService")
local market = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
function leftClick()
local player = Players.LocalPlayer
market:PromptGamePassPurchase(player, 1057151)
end
script.Parent.MouseButton1Click:Connect(leftClick)