Prompt purchase product finished

Hi, i have make a developer product in sell in my server, the product give you 500 money. but if i buy one time i gain 500 money (good) but the second time i gain 1000… the third time i gain 1500…

here’s my code:

coins1.OnServerEvent:Connect(function(plr)
		local id = 965751605
		local MarketplaceService = game:GetService("MarketplaceService")
		game:GetService("MarketplaceService"):PromptProductPurchase(plr, id)
		MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, value)
			if userId == plr.UserId and id == productId and value then 
				plr.status.Money.Value = plr.status.Money.Value + 500
			end
		end)
end)

Thats because it’ll think you bought it several times.
You need to return it.

coins1.OnServerEvent:Connect(function(plr)
		local id = 965751605
		local MarketplaceService = game:GetService("MarketplaceService")
		game:GetService("MarketplaceService"):PromptProductPurchase(plr, id)
		MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, value)
			if userId == plr.UserId and id == productId and value then 
				plr.status.Money.Value = plr.status.Money.Value + 500
		return Enum.ProductPurchaseDecision.PurchaseGranted

			end
		end)
end)

i would change this to

plr.status.Money.Value + 500

then it should work properly

Not working :confused: same issue

that won’t work, that will just set their money to 500

I want to add 500 in balance, if player have 150.000 money i don’t want to make his balance to 500 but 150.500 :slight_smile:

I will script it how I would for you. Hang on.

ik i relised i didn’t put “+” there. i edited it so it says that now

Oh ok i try it thank you :slight_smile:

PromptProductPurchase is deprecated, you should be using ProcessReceipt.

It could be part of an issue with your detecting if its finished.

So I recommend using

	MPS.ProcessReceipt = function(receiptInfo)

So if we replace everything with that, you’ll end up with this as your final product

coins1.OnServerEvent:Connect(function(plr)
		local id = 965751605
		local MarketplaceService = game:GetService("MarketplaceService")
		game:GetService("MarketplaceService"):PromptProductPurchase(plr, id)
			MPS.ProcessReceipt = function(receiptInfo)
			if receiptInfo.ProductId == 965751605 then
			local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
			player.status.Money.Value = player.status.Money.Value + 500
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
end

That’s not how you should be handling product purchases, if someone leaves before it can be completed you need to return NotProcessedYet instead of PurchaseGranted.

2 Likes

Not working i got 0 money :confused:

I believe the issue is that ProcessReceipt is within your coins1.OnServerEvent listener. As a result, you are creating a new process receipt function every time the remote event fires. As stated on the ProcessReceipt API reference, the ProcessReceipt function should only be called once by one script on the server. I would recommend copying the code at the bottom of the ProcessReceipt API reference. You can then simply create a new productFunction with your ProductId.

I have trying to copy paste the code in my server but it’s not working i don’t understand the process receipt :confused: i can’t adapt the code with my code

Copy the ProcessReceipt API code, then add this function just below the productFunctions table:

-- ProductId 965751605 for 500 Money
productFunctions[965751605] = function(receipt, player)
	-- Logic/code for player buying 500 Money
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		-- Give the player their Money
		player.status.Money.Value = player.status.Money.Value + 500
		
		-- Indicate a successful purchase
		return true
	end
end

all of this additional info your receiving is losing the main point of the post.

the script works, its just this

is what needs to be changed. it adds 500 to the player, but adds the current number on top. so if the number was 1000, it would add 1000 and 500 together. you can replace it with what i gave in my recent post,

then it will solve your problem.

Thank you ^^ i have copy paste this time and it’s working

Glad it is working for you! You should easily be able to add additional products by adding new functions in the same way. Happy scripting!

Just to clarify here: it is deprecated only to discourage developers from improperly using it to grant purchases - example being OP. The function itself isn’t (and shouldn’t be) deprecated as it’s the only form of checking when a product prompt has closed.

3 Likes