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

Trying to use a DevProduct to give a player Credits, what can I do to fix this script?

Asked by 7 years ago
local MarketplaceService=game:GetService("MarketplaceService")
local devproductid=52874408
MarketplaceService.ProcessReceipt = function(receiptInfo)
    for i,player in ipairs(game.Players:GetChildren()) do
        if receiptInfo.ProductId == devproductid then
        player.Credits.Value = player.Credits.Value + 100
        end
        end
return Enum.ProductPurchaseDecision.PurchaseGranted
    end

This is supposed to give 100 credits to the player, however, when tested in the actual game it doesn't give the player credits. It works in normal mode however

0
Heads up; You don't check the playerId, just the ProductId, wich means every player will get credits instead of the player that purchase it. RubenKan 3615 — 7y

1 answer

Log in to vote
1
Answered by
Nogalo 148
7 years ago

Here is a dev product script that you can use for any dev product you just have to change what should be done if all requirements are met. I've edited it to suit your needs so you can just copy and paste it but i do suggest you go through it and see what does what and why it's suppose to be that way

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 52874408


    MarketplaceService.ProcessReceipt = function(receiptInfo) 

    for i, player in ipairs(game.Players:GetChildren()) do

        if player.userId == receiptInfo.PlayerId then

            if receiptInfo.ProductId == productId then

            player.Credits.Value = player.Credits.Value + 100
            end
        end
    end 

    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
    ds:IncrementAsync(playerProductKey, 1)  

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
Ad

Answer this question