I'm working on a tycoon game. My leaderstats script worked fine in my test place. I don't know what happened when I moved the script to the real place. It detects the purchase (as per print statements not included here, but the money isn't deposited to the account.) Any help is appreciated!
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local PreviousPurchases = DataStoreService:GetDataStore("PreviousPurchases")
local ONE_HUNDRED_CASH = 1087391260
local ONE_THOUSAND_CASH = 1098691677
local TEN_THOUSAND_CASH = 1098695147
local ONEHUNDRED_THOUSAND_CASH = 1098701275
local ONE_MILLION_CASH = 1098706183
local TEN_MILLION_CASH = 1098713560
local ONEHUNDRED_MILLION_CASH = 1098724109
local currencyName = "Cash"
MarketplaceService.ProcessReceipt = function(receipt)
local ID = receipt.PlayerId.."-"..receipt.PurchaseId
local success = nil
pcall(function()
success = PreviousPurchases:GetAsync(ID)
end)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local player = game.Players:GetPlayerByUserId(receipt.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
else
if receipt.ProductId == ONE_HUNDRED_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 100
end
if receipt.ProductId == ONE_THOUSAND_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 1000
end
if receipt.ProductId == TEN_THOUSAND_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 10000
end
if receipt.ProductId == ONEHUNDRED_THOUSAND_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 100000
end
if receipt.ProductId == ONE_MILLION_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 1000000
end
if receipt.ProductId == TEN_MILLION_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 10000000
end
if receipt.ProductId == ONEHUNDRED_MILLION_CASH then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 100000000
end
pcall(function()
PreviousPurchases:SetAsync(ID,true)
end)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
