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

Developer Product is not adding 1 to the Value?

These scripts are supposed to add 1 to the Value of Stage when one buys the developer product but so far it is loading to purchase but** nothing is happening after you pay**.

I have 2 scripts, this one is placed inside the player:

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local player = game.Players.LocalPlayer
local stage = player.leaderstats:findFirstChild("Stage") 
CASHID = 24397415 -- Put the Developer Product ID here

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
	local numberBought = ds:IncrementAsync(playerProductKey, 1)
	for i,v in pairs (game.Players:GetChildren()) do
		if v.userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == CASHID then
						
if stage.Value < 25 then 
	stage.Value = stage.Value + 1
	wait(1)
	player.Character.Head:Remove()
end
					end
				end
			end
		end

	return Enum.ProductPurchaseDecision.PurchaseGranted	

This one is placed in the button of the GUI

local productId = 24397415 
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)	

1 comment

0

I'm not sure of it yet, but it seems that instead of creating this stage variable, rather use the v variable which stand for the player that bought the product, I'm not 100% sure but if you look at the tutorial on the roblox wiki (http://wiki.roblox.com/index.php/Developer_product) it references the player's leaderstats by using the for loop, otherwise good luck, someone will figure it out :P

1 answer

✓ Accepted answer

The problem is that you are using a LocalScript for handling the purchase, where you should be using a normal Script.

What you need to do is put the code into a normal script, get rid of the player and stage variables and then use the player found in the for loop (reference by the variable 'v' without quotes) to increase their stage value.

Also, you need to return PurchaseGranted inside your purchase handling function, otherwise you will not receive any money from ROBLOX.

Overall, your final script should look like this:

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

CASHID = 24397415 -- Put the Developer Product ID here

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
    local numberBought = ds:IncrementAsync(playerProductKey, 1)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == CASHID then
				local stats = v:WaitForChild("leaderstats") --Yields the script until leaderstats becomes available.
				local stage = stats:WaitForChild("Stage") --Same as above, but waits for the stage value in leaderstats.
				local char = v.Character --Referencing the character.
				if stage.Value < 25 then
    				stage.Value = stage.Value + 1
    				--No need for the wait. The script will wait if the character's humanoid doesn't exist yet.
					char:WaitForChild("Humanoid").Health = 0 --Waits for the humanoid then kills it by setting it's health to 0.
				end
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted --You need to return PurchaseGranted in your function, otherwise you will not recieve any money from a transaction.
end

I hope my answer helped you. If it did, be sure to accept it.

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