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

Why is cash nor wins being awarded upon purchase of Developer Product?

Code isn't working, it is a script in ServerScriptService. it is supposed to award cash upon purchase of Developer Product (not in leaderstats, it can be seen at the bottom at the screen using a text label) and wins which is in leaderstats. Can someone take a look at the code? Thanks!

local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptInfo)
    if receiptInfo == 1208410513 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.Cash.value = player.Cash.value + 100
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    if receiptInfo == 1342774613 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.Cash.value = player.Cash.value + 1000
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    if receiptInfo == 1342770170 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.Cash.value = player.Cash.value + 300
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    if receiptInfo == 1342771507 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.Cash.value = player.Cash.value + 500
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    if receiptInfo == 1343023770 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.leaderstats.Wins.value = player.leaderstats.Wins.value + 30
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    if receiptInfo == 1343022593 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.leaderstats.Wins.value = player.leaderstats.Wins.value + 10
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

6 comments

0

Missing ProductId after receiptInfo. "receiptInfo.ProductId"

0

You mean at line 3, that gives me a syntax error? Syntax Error: (3, 42) Expected ')' to close '(' at column 30), got '.'

0

If you mean after every if receiptInfo then I also tried just tried that, and it still doesn't work.

0

no he meant only in line 4, 9, 14, 19, 24, and 29

0

Yeah that's what I meant by my third comment, I had removed it from line 3 because of the syntax error but let me try the modified code you sent me.

0

It works, thank you so much! I have accepted your answer.

1 answer

✓ Accepted answer

@9mze meant only in line 4, 9, 14, 19, 24, and 29. Also, instead of individual conditions, put all of them in one condition using elseif every condition because if one condition returned, the other conditions after that condition won't run anymore. Also use .Value instead of .value with a small v.

local Players = game:GetService("Players")
local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if player then
		if receiptInfo.ProductId == 1208410513 then
			player.Cash.Value += 100
		elseif receiptInfo.ProductId == 1342774613 then
			player.Cash.Value += 1000
		elseif receiptInfo.ProductId == 1342770170 then
			player.Cash.Value += 300
		elseif receiptInfo.ProductId == 1342771507 then
			player.Cash.Value += 500
		elseif receiptInfo.ProductId == 1343023770 then
			player.leaderstats.Wins.Value += 30
		elseif receiptInfo.ProductId == 1343022593 then
			player.leaderstats.Wins.Value += 10
		end
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

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