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

How can I make the user receive the item after the purchase?

Asked by 9 years ago

I'm new to developer products and stuff. I made a developer product that gives the user ingame currency. The script works, but the user gets the currency before you press "buy". In the wiki it tells me to use datastores to keep track of who bought the developer product, why would that be necessary?

Script:

script.Parent.MouseButton1Click:connect(function()
    local Market = game:GetService("MarketplaceService")
    local id = 23747241 -- the Developer Product ID
    Market:PromptProductPurchase(game.Players.LocalPlayer, id)
    print("Bought")
    game.Players.LocalPlayer.Clashbux.Value = game.Players.LocalPlayer.Clashbux.Value + 5000
end)

1 answer

Log in to vote
-4
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
productId = 0 -- change to your id

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

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


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


            if receiptInfo.ProductId == productId then

-- I'm guessing Clashbux is in leaderstats
                player.leaderstats.Clashbux.Value = player.leaderstats.Clashbux.Value + 5000
            end
        end
    end 

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

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

KEY POINTS: receiptinfo records the purchase after receipt is processed you are able to put your next move under it the last part tells server that you handled the purchase with any other questions ask me

0
Thanks, but I would like it if you acutally EXPLAINED what the heck is going on in this script. Operation_Meme 890 — 9y
0
I don't understand a thing. Hero_ic 502 — 9y
0
Sorry I forgot explain when I answered jimborimbo 94 — 9y
0
Clashbux isnt in leaderstats. LocalPlayer finds the player and in order to get into leaderstats you gotta do "game.Players.LocalPlayer.leaderstats.Clashbux" attackonkyojin 135 — 9y
Ad

Answer this question