Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago

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
0
Missing ProductId after receiptInfo. "receiptInfo.ProductId" 9mze 193 — 1y
0
You mean at line 3, that gives me a syntax error? Syntax Error: (3, 42) Expected ')' to close '(' at column 30), got '.' AshsmithTube 15 — 1y
0
If you mean after every if receiptInfo then I also tried just tried that, and it still doesn't work. AshsmithTube 15 — 1y
0
no he meant only in line 4, 9, 14, 19, 24, and 29 T3_MasterGamer 2189 — 1y
View all comments (2 more)
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. AshsmithTube 15 — 1y
0
It works, thank you so much! I have accepted your answer. AshsmithTube 15 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

@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
Ad

Answer this question