How to make a "Steal Item" developer product similar to Grow a Garden?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m making a game sort of similar to Grow a Garden, and I’m wanting to add a developer product that players can buy in order to steal another player’s item from their plot.

  1. What is the issue? Include screenshots / videos if possible!

From what I know about how Dev Products work, you have to use a processReceipt function to handle all purchases. The problem with that is that I can’t figure out any way to directly tell the script with the processReceipt function what item the player just tried to steal. This means the server script won’t be able to give the player the item.

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

I’ve searched for solutions, but most of them are about simple devproducts that just add a currency to the player. None of the ones I’ve seen have to do with my problem.

Script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local productFunctions = {}

productFunctions[000000] = function(receiptInfo,player)
	-- player has bought the steal devproduct, but the script doesn't know what item to steal!
end

local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end
	
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = processReceipt

(sorry if I’ve done something wrong with this post, because it’s my first one)

1 Like

You can handle the steal ProximityPrompts inside of the Receipt script and save data to a table which the receipt will retrieve. That’s one of the ways and also the most simple.

3 Likes

This is the updated script, I’ve made it into a modulescript where it loops through the table and tries to find the most recent stolen item for the player. (a different script adds items to module.interactedTable when the prompt is triggered)

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local module = {}
module.interactedTable = {}

local productFunctions = {}
productFunctions[000000] = function(receiptInfo,player)
	-- tables look like this: {itemToSteal,player}
	local stolenItem
	for i=#module.interactedTable, 1, -1 do
		local currentTable = module.interactedTable[i]
		if currentTable[2] == player then
			stolenItem = currentTable[1]
		end
	end
	if not stolenItem then warn("uh oh, I accidentally scammed someone.") return end
	
	
end

local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end

	return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = processReceipt

return module

Would be cleaner to just use table.find and to store the table as the player as the index then have the value as the item to steal.

Thanks, I didn’t think about that.

I have to do the script for the client so I can actually test that this will work, but then I’ll mark your original post as the answer if it does.

Also, here’s the finished script for anyone who wants it.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local module = {}
module.interactedTable = {}

local productFunctions = {}
productFunctions[000000] = function(receiptInfo,player : Player)
	local stolenItem = module.interactedTable[player.UserId]
	if not stolenItem then warn("uh oh, I accidentally scammed someone.") return end
	
	print(stolenItem)
end

local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end

	return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = processReceipt

return module

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.