Cash DevProduct not working

No I read that very properly.

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.

How would you handle a purchase with a datastore? You need the API to change the value of the datastore then save using the datasotre.

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.

1 Like

Tried your script, unfortunately it still won’t give cash after purchase. :frowning:

Okay, will try this. Hopefully this’ll work.

Yep, I’ve got 5 of those. Do I have to get rid of other 4 ProcessReceipts?

You do. ProcessReceipt can only be assigned to once. Therefore, it’s only registering the most recent ProcessReceipt assignment and discarding the others.

After applying your fix, it started to pop up these errors on console:

– ServerScriptService.DevProductHandler:30: attempt to index a nil value
Stack Begin
Script ‘ServerScriptService.DevProductHandler’, Line 30
Stack end

Line 30 below

local cashmoney = plr:FindFirstChild("leaderstats"):FindFirstChild("Cash") if cashmoney then

plr is probably a nil value then. it is basically saying you’re trying to do something to something that does not exist.

i believe your script indexes Player as the purchaser so you are supposed to use that

local cashmoney = Player:FindFirstChild("leaderstats"):FindFirstChild("Cash") 
if cashmoney then

Does it show eny error?
30 chars

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.

Does this has to do something with Filtering?

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

switch to server side and look to game explorer, if there is the old or new value (also sry for my english, my native language is CZ)

He is using a serverscript already to set the values, please read all of the other replies before contributing. Thanks

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

Now, the console says:

– PlayerMoney is not a valid member of ServerStorage
Stack Begin
Script ‘ServerScriptService.DevProductHandler’, Line 30
Stack End

And also, word ‘cashmoney’ had a blue line below it in script.

Does that mean I’ve got to create PlayerMoney manually?

Do you use PlayerMoney for your other scripts? If it doesn’t exist then you don’t need to use it, I’m just going through your original script.

Check your other scripts and if they are using PlayerMoney you might aswell just change it to leaderstats and use that instead.

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

Are you using a tycoon kit? If you are then I’d highly recommend finding where the money is stored by switching to the server on “Play Solo”.

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