I’m making a script that will handle the developer products purchases, but I’m not sure if this is the correct way of doing it, because I heard that you need to track the purchase history to avoid issues.
For the data I’m using Suphi’s DataStore Module.
I’m really confused, so any help is appreciated!
--// Variables
local products = {}
--// Private Functions
local function setUpDonationProducts()
for id, amount in LeaderboardConfig.Donation.Products do
products[id] = function(dataStore, receiptInfo, purchaseId)
print(`add to the leaderboard {amount} robux!`)
if dataStore:Save() == "Saved" then
print(`successfully added {amount} robux to the leaderboard!`)
return Enum.ProductPurchaseDecision.PurchaseGranted
else
print(`remove {amount} robux from the leaderboard!`)
dataStore.Value.DeveloperProducts[purchaseId] = false
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
end
end
local function onProcessReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
local dataStore = DataService:GetDataStore(player, true) -- "true", means wait until the data is loaded
if not dataStore then return Enum.ProductPurchaseDecision.NotProcessedYet end
local purchaseId = receiptInfo.PurchaseId
if dataStore.Value.Developer_Products[purchaseId] and dataStore.Value.Developer_Products[purchaseId] == true then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
dataStore.Value.Developer_Products[purchaseId] = true
return products[receiptInfo.ProductId](dataStore, receiptInfo, purchaseId)
end
--// Public Functions
function ProductService:Init()
DataService = ModuleLoader.Get("DataService")
setUpDonationProducts()
MarketplaceService.ProcessReceipt = onProcessReceipt
end