Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to check when a player buys an item (?)

so this is the code im using

local player
script.Parent.MouseButton1Click:Connect(function()
	local MarketplaceService = game:GetService("MarketplaceService")
	local productID = 994379939
	player = script.Parent.Parent.Parent.Parent.Parent
	print(player)
	MarketplaceService:PromptProductPurchase(player,productID)
end)

when a player clicks on it and make a purchases i dont know how to see when a player makes the purchases the code i want it to run when a player buys it is this:

player.leaderstats.lives.Value = player.leaderstats.lives.Value + 10

2 comments

0

Is this a product or gamepass?

0

a product

1 answer

✓ Accepted answer

Use the PromptProductPurchaseFinished event.

local player
script.Parent.MouseButton1Click:Connect(function()
	local MarketplaceService = game:GetService("MarketplaceService")
	local productID = 994379939
	player = script.Parent.Parent.Parent.Parent.Parent
	print(player)
	MarketplaceService:PromptProductPurchase(player,productID)

	MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
		if isPurchased == true then -- if player purchased the product
			-- fire a RemoteEvent here to change the player's leaderstats value in a server script
		else
			print("Player did not purchase product")
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.