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

Can someone explain what exactly this developer product code is doing?

Asked by
yut640 91
8 years ago

I have NEVER worked with developer products in my entire life and I am so SO confused at what this script is doing. It is working with one ... issue ? I don't know because I don't know what it is doing. Read my notes and hopefully you are able to explain what is going on. :) Thanks!

-- setup local variables (I know this part)
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 36573978

-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo)  -- What does this do?

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


            -- check which product was purchased (again only sort of makes sense)
            if receiptInfo.ProductId == productId then

                -- handle purchase (I actually know what this does because I coded it so...)
                player.leaderstats.Simoleons.Value = player.leaderstats.Simoleons.Value + 1000
                print("success")
            end
        end
    end 

    -- record the transaction in a Data Store (what...?)
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
 --   ds:IncrementAsync(playerProductKey, 1) -- I had to remove this line, after multiple buys you would get duplicate rewards. What does this line do? Is it important? 

    -- tell ROBLOX that we have successfully handled the transaction
    return Enum.ProductPurchaseDecision.PurchaseGranted     -- yeah no idea what this is doing

end

Thank you for your time. I am still really in the basics of Lua and things like this are just not pick apartable for me because I just do not understand what is going on.

1 answer

Log in to vote
2
Answered by
Async_io 908 Moderation Voter
8 years ago
-- setup local variables (I know this part)
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 36573978

-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo)  -- Whenever you go to https://www.roblox.com/my/money.aspx#/#MyTransactions_tab it shows your receipts, which is a look at what you bought.

--Makes sure that the player on the receipt is the player getting the rewards.
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then


--Makes sure the product is the one that the player bought
            if receiptInfo.ProductId == productId then

                -- handle purchase (I actually know what this does because I coded it so...)
                player.leaderstats.Simoleons.Value = player.leaderstats.Simoleons.Value + 1000
                print("success")
            end
        end
    end 

--Records this in the datastore, which is a save system roblox has.
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
 --   ds:IncrementAsync(playerProductKey, 1) --I'm pretty sure this line is important. It allows developer products to be purchased over and over again, which is the entire point of dps. If you didn't want this, there's always gamepasses.

 --This tells roblox that the purchase finished, the player had enough money, and it had no errors buying it.
    return Enum.ProductPurchaseDecision.PurchaseGranted 

end

0
(This is based on my version of common sense, as I have never used dps as well. Async_io 908 — 8y
0
When the ds:Increment thing was in the original code, every time I bought it multiple times it would give me first +1000 then +2000 then +3000 (so i end up with 6000 total) after removing it this was prevent and it adds correctly. Any ideas why? Accepted your answer though because it helped a lot :) yut640 91 — 8y
0
I'm a bit surprised and didn't know that was a thing. Must be an optional line for if you feel like you want/need it. Async_io 908 — 8y
Ad

Answer this question