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

Developer Product not giving coins on purchase?

Asked by 6 years ago

Hello, I am new to Developer Products, so please don't call me a "Noob" I need help with this script, where when somebody is prompted to purchase it in another script, this one fires, then gives the player coins. However, none of this happens, so the Player only wastes ROBUX. Here is the ServerScript:

local MarketplaceService = game:GetService("MarketplaceService")
local IdOne, IdTwo, IdThree, IdFour, IdFive, IdSix = 98320218, 98320249, 98321378, 98321410, 98324883, 98325157
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

function MarketplaceService.ProcessReceipt(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
    end

    -- find the player based on the PlayerId in receiptInfo
    local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then -- Seems like we can't find the player... already left?
        return Enum.ProductPurchaseDecision.NotProcessedYet -- Can't process
    end

    if receiptInfo.ProductId == IdOne then
        player.Stats.Coins.Value = player.Stats.Coins.Value + 10
    elseif receiptInfo.ProductId == IdTwo then
        player.Stats.Coins.Value = player.Stats.Coins.Value + 25
    elseif receiptInfo.ProductId == IdThree then
        player.Stats.Coins.Value = player.Stats.Coins.Value + 150
    elseif receiptInfo.ProductId == IdFour then
        player.Stats.Coins.Value = player.Stats.Coins.Value + 500
    elseif receiptInfo.ProductId == IdFive then
        player.Stats.Coins.Value = player.Stats.Coins.Value + 1500
        elseif receiptInfo.ProductId == IdSix then
        player.Stats.Coins.Value = player.Stats.Coins.Value + 6000
    end
    -- record the transaction in a Data Store
    PurchaseHistory:SetAsync(playerProductKey, true)    
    -- tell ROBLOX that we have successfully handled the transaction (required)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
0
Just because you are not familiar with a section of Roblox Lua, does not make you a noob. Also, handle datastore calls in a protected call, as they sometimes fail. hiimgoodpack 2009 — 6y
0
If the datastore fails, just return Enum.ProductPurchaseDecision.NotProcessedYet hiimgoodpack 2009 — 6y
0
But what about it not giving the coins? TinyScripter 70 — 6y
0
Like I said, if the datastore fails, tell the user. It might be failing. hiimgoodpack 2009 — 6y
0
Please accept my answer PyccknnXakep 1225 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Refer to this ROBLOX Wiki article here. This should help you a lot. Please accept my answer if this helped!

0
THANKS SOOOO MUCH! TinyScripter 70 — 6y
0
^Please accept my answer. PyccknnXakep 1225 — 6y
Ad

Answer this question