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

I need help with Marketplace Service [Still Un-answered] please?

Asked by
hiccup111 231 Moderation Voter
10 years ago

The short of it is, I don't recieve money on purchase.

What I have running, in ServerScriptService, as a Server-Sided Script:

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

-- 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
            player.Teleport.Value = false wait() player.Teleport.Value = true
        end
    end 

    -- record the transaction in a Data Store
    local playerProductKey = receiptInfo.PlayerId .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)  

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

This was copied from the demo place I found in the Roblox Wiki (http://www.roblox.com/Developer-Product-Sample-place?id=147965737).

the local 'playerProductKey' (line 14) used to be longer, but used to produce errors: 'key is too long' or something.

Shortening that fixed the errors, but still it won't pay me.

Please tell me if you see something that may cause this to not work.

1 answer

Log in to vote
1
Answered by
Gamenew09 180
10 years ago

Why do you have two functions like this?

...
MarketplaceService.ProcessReceipt = function(receiptInfo)
    MarketplaceService.ProcessReceipt = function(receiptInfo)
        ...
    end
end

You have nested the main ProcessRecipt function in the other function for it.

Remove the outside function to make it look like this:

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

MarketplaceService.ProcessReceipt = function(receiptInfo)
        for i, player in pairs(game.Players:GetChildren()) do
            if player.userId == receiptInfo.PlayerId then
                player.Teleport.Value = false
                player.Teleport.Value = true
            end
        end

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

        return Enum.ProductPurchaseDecision.PurchaseGranted
end

That should fix it.

If I helped vote this answer up along with accepting! It helps me and other people in the long run.

0
This was an old post, I forgot it had the nested function in it. I found that, but still it doesn't give me money back. hiccup111 231 — 10y
Ad

Answer this question