Developer products, purchasing currency, PLEASE HELP!

try this (i havent tested it so it might not work)
tell me any errors you get btw
this documentation text explains some of the modified code: MarketplaceService | Documentation - Roblox Creator Hub

-- -- 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
    plr.leaderstats.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. --
MarketplaceService.ProcessReceipt = function(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
	
	local handler = productFunctions[reciept.ProductId]
	local s, e = pcall(function(handler, reciept, player)
	if s then return Enum.ProductPurchaseDesicion.PurchaseGranted else warn(e) return Enum.ProductPurchaseDecision.NotProcessedYet end
end
1 Like

I get no errors, and it still doesn’t work, the purchase goes through, and also FYI: The value is coin and it is not in leaderstats it is a folder called mainData which the value is called “Coins”. Again, please help. I really need to get this game out :roll_eyes:

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
    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)
	if s then return Enum.ProductPurchaseDesicion.PurchaseGranted prin("supposedly went through") else warn(e) return Enum.ProductPurchaseDecision.NotProcessedYet end
end

MarketplaceService.ProcessReceipt = procRec

try USE THE EDITED VERSION

1 Like

the code has errors. and it is kinda difficult to understand.


???
please help me. thanks

1 Like

i meant output errors not code errors sry

1 Like

no. the code you sent me has errors.

1 Like

I want to see the output first. The code shouldn’t have errors. Just try running it once and show me the output errors.

1 Like


and btw i changed “prin” to print because thats what was there

1 Like


and as you can see tons of red underlines. in your code

1 Like

for that line of code try the following

if s then print("supposedly went through") return Enum.ProductPurchaseDesicion.PurchaseGranted elseif not s then warn(e) return Enum.ProductPurchaseDecision.NotProcessedYet end
1 Like

oh wait i see whats going on
where it says local s,e = pcall(function... you want to remove function and that open parenthesisto the right of it (you still want to use the previous line of code too though)

1 Like

like this?

1 Like

hello?

char limit char limit char limit char limit

1 Like

show me your full script your messing with it a bit

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)
		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! :+1:

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