Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 comment

1 answer

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.

2 comments

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.