I am trying to make a credit shop, and when they buy the dev. product it adds 10 credits to their value When I buy the product it doubles the amount that I already have (ex. I start with 110, and buy it now I have 220... I should only be getting ten)
Heres the script :
local player = game.Players.LocalPlayer local cash = game.Players.LocalPlayer.Cash function CompletePurchase() wait(1) player.Cash.Value = player.Cash.Value + 10 end local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 23429504 MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == productId then CompletePurchase() end end end local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end
There is also another script :
local buy = script.Parent local productId = 23429504 buy.MouseButton1Click:connect(function() game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId) end)
Assuming this is part of a leaderboard do this if not give me the script or scripts associated with that cash value.
player.leaderstats.Cash.Value=player.leaderstats.cash.Value+10
Note that the API states that you must only set "ProcessReceipt" once and you should do it ServerSide. The function is expected to be able to handle any/all purchases, not just of a specific type.
If you make this change and still have issues, add a record of what receipt IDs have been dealt with and if the current receipt ID is in that dictionary, return immediately. ex:
idsDealtWith = {} MarketplaceService.ProcessReceipt = function(receiptInfo) if idsDealtWith[receiptInfo.PurchaseId] then return Enum.ProductPurchaseDecision.PurchaseGranted end idsDealtWith[receiptInfo.PurchaseId] = true --rest of code here end
The API actually recommends this code:
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") MarketplaceService.ProcessReceipt = function(receiptInfo) local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId if PurchaseHistory:GetAsync(playerProductKey) then return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it. end --deal with purchase here PurchaseHistory:SetAsync(playerProductKey, true) return Enum.ProductPurchaseDecision.PurchaseGranted end