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

Dev product not working?

Hi guys! I have tried really hard to get this working and still cannot fix it :/ I would really appreciate it if you could help me! Thanks!

Any ideas why this isn't awarding the 100 coins? The transaction goes through fine.

Script in gui button :

local MarketplaceService = game:GetService("MarketplaceService")

local productId = 25851870

MarketplaceService.ProcessReceipt = function(receiptInfo) 


	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == receiptInfo.PlayerId then

 
			if receiptInfo.ProductId == productId then

			
				player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100
				return Enum.ProductPurchaseDecision.PurchaseGranted		
			end
		end
	end	
 end

localscript in starterpack:

wait(1)
local stuff = game.Players.LocalPlayer.PlayerGui.ShopGUI.ShopFrame.Page7.Descriptions1.Buynow
local productId = 25851870 -- change to your developer product ID
stuff.MouseButton1Click:connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

1 answer

-- Inside a server script.
local MarketplaceService = game:GetService("MarketplaceService")
local id= 25821928
local event = Instance.new("RemoteEvent") -- Remote events can be fired via a local script, causing the two to be linked.
event.Parent = game.Workspace 
event.Name = "DataStoreEvent"  
event.OnServerEvent:connect(function()
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") --Getting the data store service
 
MarketplaceService.ProcessReceipt = function(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
   
    for i, plr in ipairs(game.Players:GetPlayers()) do
        if plr.userId == receiptInfo.PlayerId then
            
            if receiptInfo.ProductId == id then		
						plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value +1000
					
			end
        end	
    end
    PurchaseHistory:SetAsync(playerProductKey, true)
    return Enum.ProductPurchaseDecision.PurchaseGranted		
end	
end)
-- Inside a local script.
local MarketplaceService = game:GetService("MarketplaceService")
local buyButton = game.Workspace["Coin Stand"].Part.SurfaceGui.Frame["1000"]
local player = game.Players.LocalPlayer
local id = 25821928

buyButton.MouseButton1Click:connect(function()
		
	MarketplaceService:PromptProductPurchase (player, id, true,  2)

 

game.Workspace.DataStoreEvent:FireServer() -- Calling in the RemoteEvent


end)

Wiki Page on Remote Functions and Events

Wiki page on Processing receipts

I think your problem is that you're not using a remote event, read up.

2 comments

0

Thanks! The transaction goes through but it doesn't award the coins though :/

0

Are you using a remote event? Set up an event and make sure you get the data store service.

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