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

Why is this developer product script not working?

Why is this script for my developer product not working?

productId = 20008845


function onClick(Clicker) 
	Player = game.Players:GetPlayerFromCharacter(Clicker.Parent)
	game:GetService("MarketplaceService"):PromptProductPurchase(Player, productId)
end
MS = game:GetService("MarketplaceService")
PH = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MS.ProcessReceipt = function(RI)
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.UserId == RI.PlayerId then
			if RI.ProductId == productId then
				player.Character.Health = 0
			end
		end
	end
	playerProductKey = "player_" .. RI.PlayerId .. "_purchased_" .. RI.PurchaseId
	PurchaseHistory.IncrementAsync(playerProductKey, 1)
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

script.Parent.MouseClick:connect(onClick)

Thank you!

1 answer

✓ Accepted answer

Well, you didn't have to get the children of players to make this work properly. From looking at the connection line, I see that it's a click detector.

sp = script.Parent
id = 20064983 --dev product id

sp.ClickDetector.MouseClick:connect(function(p)
	game:GetService("MarketplaceService"):PromptProductPurchase(p, id)
	local MarketplaceService = Game:GetService("MarketplaceService")
	local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
	MarketplaceService.ProcessReceipt = function(receiptInfo) 
		if p.userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == id then
				p.Character.Humanoid.Health = 0
				-- Alternative to kill them V
				-- p.Character:BreakJoints()
			end
	
	-- record the transaction in a Data Store
	local playerProductKey = receiptInfo.PlayerId .. "_got_" .. receiptInfo.PurchaseId
	ds:IncrementAsync(playerProductKey, 1)	
	
	-- tell ROBLOX that we have successfully handled the transaction
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end
	
	end
end)

2 comments

0

it works! Thank you!

0

No problem.

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