You can write your topic however you want, but you need to answer these questions:
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.
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.
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)
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.
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
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