This is what you said. And I’m telling you that you aren’t supposed to handle developer products with DataStores. Handling aftermath data once it’s set post-process is fine; handling a purchase itself with a DataStore is not.
You don’t handle a purchase with a DataStore. Saving and processing purchases are two different pipelines. Saving isn’t involved here and it’s unrelated to the OP in the first place, who’s having trouble with ProcessReceipt and not saving data.
You do. ProcessReceipt can only be assigned to once. Therefore, it’s only registering the most recent ProcessReceipt assignment and discarding the others.
Thanks for fix, now it finally ads cash to the leaderboard. However, there is another issue.
The purchased cash is not valid!
l’ll try to explain the best, English is not my native:
It does add cash to leaderboard after purchasing, I’ve purchased 300 cash so I can purchase something for 250, however, it won’t buy it after touching the purchase brick.
Technically ingame cash is still the same before any cash was purchased. After I collect cash from cash collector, it would reset to the ‘real count’.
It does like, for example, you’ve earned 300 from cash collector, but you purchased 100 coins, so leaderboard says you’ve got 400. However, after purchase if you collect any money (like 5 cash), it’ll set leaderboard cash to 305. Even if you don’t collect anything, purchased cash won’t be valid.
Your other script could be checking the money stat in ServerStorage, I’d just advise using leaderstats for less complexity and so you don’t have to change it in both.
Otherwise, correctly set the stat in both ServerStorage and leaderstats.
local leadStat, storStat= Player:FindFirstChild("leaderstats"):FindFirstChild("Cash"), game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
if leadStat and storStat then
-- Add cash to both
Ok so pls can you export this part of game to single place and upload it, because its easier to solve problem on my own computer, that to navigate someone
pls it will be very useful to give us the giving script, the script adding the stats and at least 1 buy script (or any script changing the money) in place, that you upload, so i can easier see the mistake
If I don’t need to use it, then why console informs me that PlayerMoney is not in ServerStorage?
Anyway, here’s the script after all the fixes
game.StarterGui.ResetPlayerGuiOnSpawn = false
old_fog = game.Lighting.FogStart
local MarketplaceService = game:GetService("MarketplaceService")
function getPlayerFromId(id)
for i,v in pairs(game.Players:GetChildren()) do
if v.userId == id then
return v
end
end
return nil
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
local productId = receiptInfo.ProductId
local playerId = receiptInfo.PlayerId
local player = getPlayerFromId(playerId)
local productName
-- Down below is an example of a Cash boost
-------------------------------------------------------------------
if productId == 736318162 then
local leadStat, storStat= player:FindFirstChild("leaderstats"):FindFirstChild("Cash"), game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
if leadStat and storStat then
cashmoney.Value = cashmoney.Value + 100
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end