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

Help with Developer Product not giving the Player coins when purchased?

Asked by 6 years ago
Edited 6 years ago

Hello, I am currently trying to figure out how to make this Developer Product give the player who bought this 500 coins when purchased, however, It won't do that. Here is the LocalScript in StarterGui:

local buyButton = game.Workspace.BuyCoins.Buy["500Coins"]
local productId = 98321410

buyButton.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

That part works, but here is the Script inside the button with the part that doesn't work:

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

-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo) 

    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then


            -- check which product was purchased
            if receiptInfo.ProductId == productId then

                -- handle purchase
                player.Stats.Coins.Value = player.Stats.Coins.Value + 500
            end
        end
    end 
 local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
    ds:IncrementAsync(playerProductKey, 1)

    -- tell ROBLOX that we have successfully handled the transaction
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

Answer this question