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

Why isn't this marketplace service working?

I'm working on a PlayerPoints shop, where you can buy player points with Robux. For some reason, the script errors out in game. Can anyone figure out what is wrong? Thanks.

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

local twoPoints = 19642067
local fivePoints = 19642318
local tenPoints = 19642331
local fiftyPoints = 19642337
local hundredPoints = 19642339

MarketplaceService.ProcessReceipt = function(receiptInfo) 
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == twoPoints then
				points:AwardPoints(player.userId, 2)
			elseif receiptInfo.ProductId == fivePoints then
				points:AwardPoints(player.userId, 5)
			elseif receiptInfo.ProductId == tenPoints then
				points:AwardPoints(player.userId, 10)
			elseif receiptInfo.ProductId == fiftyPoints then
				points:AwardPoints(player.userId, 50)
			elseif receiptInfo.ProductId == hundredPoints then
				points:AwardPoints(player.userId, 100)
			end
		end
	end	
	
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
	ds:IncrementAsync(playerProductKey, 1)	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end
	

3 answers

Well, I am working with my own Developer Products right now and here is my script (It works entirely, except that it gives multiple M1911s instead of just one for some reason...)

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

MarketplaceService.ProcessReceipt = function(receiptInfo) 

	for i, player in ipairs(game.Players:GetChildren()) do
		
		if player.userId == receiptInfo.PlayerId then
			
			if receiptInfo.ProductId == productId then
				game.Lighting:FindFirstChild("Obitor"):Clone().Parent = player.Backpack
				game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased an illegal M1911."
		end
	end
end
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
	ds:IncrementAsync(playerProductKey, 1)	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

6 comments

0

Maybe it's because I was using game.Players:GetChildren() instead of game.Players:GetPlayers()? Would that affect it at all?

0

I am also using GetChildren() and it works fine other than receiving multiple weapons... Here is what I can think of- Do you have a LocalScript inside StarterPack? If so, what does that LocalScript contain?

0

I have multiple local scripts inside of the StarterGui, which prompt the players to buy the developer products.

0

In that case, are you prompted to purchase them?

0

What do you mean? :P

0

When you perform whatever action that is required to call PromptProductPurchase, are you prompted to purchase the Dev Product?

Is it possibly because you have it awarding points? That's probably why.

Also, what is the output errors?

local MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo) game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId -- ... -- use DataStore to record purchase -- ... return Enum.ProductPurchaseDecision.PurchaseGranted end

                                                     or

local MarketplaceService = Game:GetService("MarketplaceService") local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton local productId = 13672652

buyButton.MouseButton1Click:connect(function() MarketplaceService:PromptProductPurchase(player, productId) end)

                                                     or go here:

http://wiki.roblox.com/index.php?title=Special%3ASearch&profile=default&search=MarketPlace+Service&fulltext=Search

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