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

Developer Product Value?

I am trying to work on this in my game, and when I buy the product it does not give me my credits.

local service = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer

local buyButton = script.Parent
local productId = 23429504

buyButton.MouseButton1Click:connect(function()
game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
if service:PlayerOwnsAsset(game.Players.LocalPlayer, productId) then
game.Players.LocalPlayer = game.Players.LocalPlayer + 10
end
end)

4 comments

0

Code block please

0

fixed

0

I believe you shouldn't be activating what will happen with the Product in the Client script. Do it within your Server Sided. Look at Uristmcsparx example for ROBLOX Wiki

0

@alpha, he's not defining the ProcessReceipt in his localscript, so it's fine. The ProcessReceipt is what controls what happens when someone purchases a Developer Product. If he were then that would be a problem, but he's not.

2 answers

In order for you to obtain anything from buying a Developer Product, you need to define the ProcessReceipt of MarketPlaceService.

Read more here

NOTE: The ProcessReceipt can only be defined in a server script(regular script) - attempting to define it in a localscript will cause it to not work.

Your script would error, to fix this figure out where the cash is. This is the server's side of the script.

function CompletePurchase()
	--This will error below, may need to know what you really want it to do.
	game.Players.LocalPlayer = game.Players.LocalPlayer + 10
end

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

MarketplaceService.ProcessReceipt = function(receiptInfo) 
 

	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == receiptInfo.PlayerId then
 
 
			if receiptInfo.ProductId == productId then
 
				CompletePurchase()
			end
		end
	end	
 
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
	ds:IncrementAsync(playerProductKey, 1)	
 
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

Here's the player's side:

local buy = script.Parent
local productId = 23429504

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

I will say that I don't know where the BuyButton is, so you'll have to change buy to where its at. The server's side goes in the model. The player's side goes in a local script in the StarterPack and possibly in the model in which that may make it even easier. Tell me if there's any errors.

4 comments

0

Why are you adding 10 to localplayer?

0

I followed what the original script has it do.

0

Line 10; The original script.

0

I know it will error, if I can get a hold with him then I'll tell him that it will error.

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