I usually do it this way: I create a method that checks for a specific purchase, if it is, it returns true and does the necessary actions. Otherwise, it goes further. through the methods.
InAppService ServerScipt
local marketplaceService = game.MarketplaceService;
local robuxSeedPrices = require(game.ReplicatedStorage.RobuxPrices);
local function CheckBuySeedInApps(player, id)
local items = robuxSeedPrices.GetPricesTable();
for i, item in pairs(items) do
if (tonumber(item.pruchaseID) == id) then
game.ServerScriptService.PlayerResourcesService.AddPlantInventory:Invoke(player, i, true);
return true;
end
end
return false;
end
local function CheckRestockBuy(player, id)
if (tonumber(robuxSeedPrices.GetRestock().pruchaseID) == id) then
game.ServerScriptService.ShopSeedsService.ResetFunction:Invoke()
return true;
end
return false;
end
local function CheckGift(player, id)
if (tonumber(robuxSeedPrices.GeGift().pruchaseID) == id) then
game.ReplicatedStorage.SendGiftEvent:FireClient(player);
return true;
end
return false;
end
marketplaceService.ProcessReceipt = function(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
local id = receiptInfo.ProductId;
if (CheckBuySeedInApps(player, id)) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
if (CheckRestockBuy(player, id)) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
if (CheckGift(player, id)) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
RobuxPrices Table
local prices = {}
function prices.GetPricesTable()
local data = {
[0] = {
name = "Carrot",
pruchaseID = "3362900675",
itemPrice = 5
},
[2] = {
name = "Apple",
pruchaseID = "3362901056",
itemPrice = 15
},
[4] = {
name = "Pumpkin",
pruchaseID = "3362901669",
itemPrice = 13
},
[6] = {
name = "Tomato",
pruchaseID = "3362902236",
itemPrice = 20
},
[8] = {
name = "Cactus",
pruchaseID = "3362902669",
itemPrice = 50
},
[10] = {
name = "Glow Mushroom",
pruchaseID = "3362903101",
itemPrice = 100
},
[11] = {
name = "Truffle",
pruchaseID = "3362903741",
itemPrice = 25
},
[13] = {
name = "Watermelon",
pruchaseID = "3370565613",
itemPrice = 15
},
[15] = {
name = "Bamboo",
pruchaseID = "3370565941",
itemPrice = 18
}
}
return data;
end
function prices.GetSeedById(id)
return prices.GetPricesTable()[id];
end
function prices.GetRestock()
return {
name = "Restock",
pruchaseID = "3363202883",
itemPrice = 79
};
end
function prices.GeGift()
return {
name = "Gift",
pruchaseID = "3363285573",
itemPrice = 60
};
end
return prices