How would I detect when a player has purchased a gamepass?

Hi, I have made a leaderstats value for ‘donated’ and I want to make it so that when the player purchases a gamepass, it adds to the ‘donated’ value.
I have got about 10 buttons, which all link the player to purchasing a t-shirt. Under each button I have a local script saying:

local id = 11397896147

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, id)
end)

How would I add to this script to make it so that it can detect if the player actually bought the t shirt and then add to the leaderstats value?

You can use the MarketplaceService.PromptGamePassPurchaseFinished event.

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, wasPurchased)
   if wasPurchased then
      print(player.Name .. " purchased game pass with id: " .. passId)
   end
end)
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.