Connecting a function to a player buying a gamepass?

I’m trying to make a system to buy houses/apartments.

I’m aware of the PromptGamePassPurchaseFinished function but this will call a function even if the player cancels the purchase. How would I make a function that will only work if the player actually buys the item?

My current code:

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(p, id)
	local c = soldsign:GetChildren()
	for i,c in pairs (c) do
		c.Transparency = 0
	end
	buysign:Destroy()
end)

Thanks!

There’s a 3rd return which determines if the player bought something or not, just check if that 3rd return is false and if so do nothing

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(p, id, bought)
    if not bought then
        return
    end
	local c = soldsign:GetChildren()
	for i,c in pairs (c) do
		c.Transparency = 0
	end
	buysign:Destroy()
end)
1 Like