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

Developer Product not giving coins on purchase?

Hello, I am new to Developer Products, so please don't call me a "Noob" I need help with this script, where when somebody is prompted to purchase it in another script, this one fires, then gives the player coins. However, none of this happens, so the Player only wastes ROBUX. Here is the ServerScript:

local MarketplaceService = game:GetService("MarketplaceService")
local IdOne, IdTwo, IdThree, IdFour, IdFive, IdSix = 98320218, 98320249, 98321378, 98321410, 98324883, 98325157
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
 
function MarketplaceService.ProcessReceipt(receiptInfo) 
	local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
	if PurchaseHistory:GetAsync(playerProductKey) then
		return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
	end
 
   	-- find the player based on the PlayerId in receiptInfo
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then -- Seems like we can't find the player... already left?
		return Enum.ProductPurchaseDecision.NotProcessedYet -- Can't process
	end
 
	if receiptInfo.ProductId == IdOne then
		player.Stats.Coins.Value = player.Stats.Coins.Value + 10
	elseif receiptInfo.ProductId == IdTwo then
		player.Stats.Coins.Value = player.Stats.Coins.Value + 25
	elseif receiptInfo.ProductId == IdThree then
		player.Stats.Coins.Value = player.Stats.Coins.Value + 150
	elseif receiptInfo.ProductId == IdFour then
		player.Stats.Coins.Value = player.Stats.Coins.Value + 500
	elseif receiptInfo.ProductId == IdFive then
		player.Stats.Coins.Value = player.Stats.Coins.Value + 1500
		elseif receiptInfo.ProductId == IdSix then
		player.Stats.Coins.Value = player.Stats.Coins.Value + 6000
	end
	-- record the transaction in a Data Store
	PurchaseHistory:SetAsync(playerProductKey, true)	
	-- tell ROBLOX that we have successfully handled the transaction (required)
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

5 comments

0

Just because you are not familiar with a section of Roblox Lua, does not make you a noob. Also, handle datastore calls in a protected call, as they sometimes fail.

0

If the datastore fails, just return Enum.ProductPurchaseDecision.NotProcessedYet

0

But what about it not giving the coins?

0

Like I said, if the datastore fails, tell the user. It might be failing.

0

Please accept my answer

1 answer

✓ Accepted answer

Refer to this ROBLOX Wiki article here. This should help you a lot. Please accept my answer if this helped!

2 comments

0

THANKS SOOOO MUCH!

0

^Please accept my answer.

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