So, I have redone how my developer products are functioning. I used this place, "http://www.roblox.com/games/147965737/Developer-Product-Sample" that was on the wiki to help me out. All I did was change the ProductID and then changed the purchase part to give coins instead. I wanted it so that when they buy the product they are awarded 500 'SpiritCoins', though every time I buy it to test it, it gives random amounts each time. It has awarded me 10000, 20000, 30000, 50000, 100000, and 300000. I have NO CLUE why it is random each time I do it when I dont even touch the code each time I buy it. Can anyone help me out please? Thank you!
-- setup local variables local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 26121381 game.Players.PlayerAdded:connect(function() print("start") local DeveloperProducts = game:GetService("MarketplaceService"):GetDeveloperProductsAsync():GetCurrentPage() for _, DevProductContainer in pairs(DeveloperProducts) do for Field, Value in pairs(DevProductContainer) do print(Field .. ": " .. Value) end print(" ") end print("end") end) -- define function that will be called when purchase finished MarketplaceService.ProcessReceipt = function(receiptInfo) -- find the player based on the PlayerId in receiptInfo for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then -- check which product was purchased if receiptInfo.ProductId == productId then -- handle purchase. In this case we are healing the player. player.leaderstats.SpiritCoins.Value = player.leaderstats.SpiritCoins.Value + 500 -- more feedback for the player. game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased 500 Spirit Coins." end end end -- record the transaction in a Data Store local playerProductKey = "p_" .. receiptInfo.PlayerId .. "_p_" .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) -- tell ROBLOX that we have successfully handled the transaction return Enum.ProductPurchaseDecision.PurchaseGranted end
I'm not 100% but, to me it looks as if the process Receipt is being called multle times, naturally, to ensure the purchase follows through correctly.
You could try a short denounce:
-- find the player based on the PlayerId in receiptInfo for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then -- check which product was purchased if receiptInfo.ProductId == productId and not player:FindFirstChild("purchaseDebounce") then deb =Instance.new("IntValue",player) deb.Name = "purchaseDenounce" game.Debris:AddItem(deb,0.1) -- handle purchase. In this case we are healing the player. player.leaderstats.SpiritCoins.Value = player.leaderstats.SpiritCoins.Value + 500 -- more feedback for the player. game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased 500 Spirit Coins." end end end