-- -- Written by @DevKeia on 8/1/23 --
-- As most customizable allowed scripts, we do have certain comments in here! --
local MarketplaceService = game:GetService("MarketplaceService") -- Marketplace --
local DatastoreService = game:GetService("DataStoreService") -- Service for DS --
local PreviousPurchases = DatastoreService:GetDataStore("PreviousPurchases") -- creates the datastore --
local productFunctions = {} -- this table will contain all of product ids and functions
local ONE_HUNDRED_CASH = 1597416227 -- 100 cash id --
local FOUR_HUNDRED_FIFTY_CASH = 1597417372 -- 450 cash id --
local ONE_THOUSAND_CASH = 1597417917 -- 1000 cash id --
local TEN_THOUSAND_CASH = 1597418310 -- 10000 cash id --
local function giveCash(plr, amt) -- this function will simply give the player cash
wait(1)
plr.mainData.Cash.Value += amt
end
productFunctions[ONE_HUNDRED_CASH] = function(info, plr) -- gives plr 100 cash
giveCash(plr, 100)
end
productFunctions[FOUR_HUNDRED_FIFTY_CASH] = function(info, plr) -- gives plr 450 cash
giveCash(plr, 450)
end
productFunctions[ONE_THOUSAND_CASH] = function(info, plr) -- gives plr 1000 cash
giveCash(plr, 1000)
end
productFunctions[TEN_THOUSAND_CASH] = function(info, plr) -- gives plr 10000 cash
giveCash(plr, 10000)
end
-- when a devproduct is bought in game, it will look through this function. --
local function procRec(reciept)
local ID = reciept.PlayerId.."-"..reciept.PurchaseId -- not relevant but did you mean to put ProductId here instead of PurchaseId?
if PreviousPurchases:GetAsync(ID) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local player = game.Players:GetPlayerByUserId(reciept.PlayerId)
if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
print(1)
local handler = productFunctions[reciept.ProductId]
print(2)
local s, e = pcall(function(handler, reciept, player)
print(3)
local s, e = pcall(handler, reciept, player)
if s then print("supposedly went through") return Enum.ProductPurchaseDesicion.PurchaseGranted elseif not s then warn(e) return Enum.ProductPurchaseDecision.NotProcessedYet end
end)
end
MarketplaceService.ProcessReceipt = procRec
1 Like
You can try my module, PurchaseLib, itās exactly for that, developer products:
PurchaseLib - Handling developer product purchases | Developer Forum
You can learn more about it in the devforum post I linked above.
1 Like
I look into it! Thanks for sharing your work in community resources!
2 Likes
If you have any question about how to set it up, ask me and I will help you.
If thereās something youād want me to add to the āmoduleā or just give me feedback, you can do so in the devforum post I linked earlier!
1 Like
I sent you a PM on dev forum
char limit
1 Like
-- -- Written by @DevKeia on 8/1/23 --
-- As most customizable allowed scripts, we do have certain comments in here! --
local MarketplaceService = game:GetService("MarketplaceService") -- Marketplace --
local DatastoreService = game:GetService("DataStoreService") -- Service for DS --
local PreviousPurchases = DatastoreService:GetDataStore("PreviousPurchases") -- creates the datastore --
local productFunctions = {} -- this table will contain all of product ids and functions
local ONE_HUNDRED_CASH = 1597416227 -- 100 cash id --
local FOUR_HUNDRED_FIFTY_CASH = 1597417372 -- 450 cash id --
local ONE_THOUSAND_CASH = 1597417917 -- 1000 cash id --
local TEN_THOUSAND_CASH = 1597418310 -- 10000 cash id --
local function giveCash(plr, amt) -- this function will simply give the player cash
wait(1)
plr.mainData.Cash.Value += amt
end
productFunctions[ONE_HUNDRED_CASH] = function(info, plr) -- gives plr 100 cash
giveCash(plr, 100)
end
productFunctions[FOUR_HUNDRED_FIFTY_CASH] = function(info, plr) -- gives plr 450 cash
giveCash(plr, 450)
end
productFunctions[ONE_THOUSAND_CASH] = function(info, plr) -- gives plr 1000 cash
giveCash(plr, 1000)
end
productFunctions[TEN_THOUSAND_CASH] = function(info, plr) -- gives plr 10000 cash
giveCash(plr, 10000)
end
-- when a devproduct is bought in game, it will look through this function. --
local function procRec(reciept)
local ID = reciept.PlayerId.."-"..reciept.PurchaseId -- not relevant but did you mean to put ProductId here instead of PurchaseId?
if PreviousPurchases:GetAsync(ID) then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local player = game.Players:GetPlayerByUserId(reciept.PlayerId)
if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
print(1)
local handler = productFunctions[reciept.ProductId]
print(2)
local s, e = pcall(function()
handler(reciept, player)
end)
if s then print("supposedly went through") return Enum.ProductPurchaseDesicion.PurchaseGranted elseif not s then warn(e) return Enum.ProductPurchaseDecision.NotProcessedYet end
end
MarketplaceService.ProcessReceipt = procRec
1 Like