Developer products, purchasing currency, PLEASE HELP!

  1. What do you want to achieve? A developer product that when you buy it your currency increases

  2. What is the issue? The currency does not increase, even with correct coding!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes. Nothing seems to work :frowning:

This is my code below.
( SERVER )

-- -- 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 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 --


-- when a devproduct is bought in game, it will look through this function. --
MarketplaceService.ProcessReceipt = function(reciept)
	
	
	local ID = reciept.PlayerId.."-"..reciept.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
		
	else
		if reciept.ProductId == ONE_HUNDRED_CASH then
			print("found data")
			player.mainData.Coins.Value = player.mainData.Coins.Value + 100
		else
			if reciept.ProductId == FOUR_HUNDRED_FIFTY_CASH then
				player.mainData.Coins.Value = player.mainData.Coins.Value + 450
			else
				if reciept.ProductId == ONE_THOUSAND_CASH then
					player.mainData.Coins.Value = player.mainData.Coins.Value + 1000
				else
					if reciept.ProductId == TEN_THOUSAND_CASH then
						print("found data")
						player.mainData.Coins.Value = player.mainData.Coins.Value + 10000
					else
						print("unfourtanely, this product purchase has absoultely nothing to do with coins so stop. thx")
					end
				end
			end
		end
	end
end

CLIENT:

local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(player, 1597416227)
end)

Please help me! Thank you!

3 Likes

Replace server code with this:

-- -- 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 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 --


-- when a devproduct is bought in game, it will look through this function. --
MarketplaceService.ProcessReceipt = function(reciept)


	local ID = reciept.PlayerId.."-"..reciept.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

	else
		if reciept.ProductId == ONE_HUNDRED_CASH then
			print("found data")
			player.mainData.Coins.Value = player.mainData.Coins.Value + 100
		elseif reciept.ProductId == FOUR_HUNDRED_FIFTY_CASH then
			player.mainData.Coins.Value = player.mainData.Coins.Value + 450
		elseif reciept.ProductId == ONE_THOUSAND_CASH then
			player.mainData.Coins.Value = player.mainData.Coins.Value + 1000
		elseif reciept.ProductId == TEN_THOUSAND_CASH then
			player.mainData.Coins.Value = player.mainData.Coins.Value + 10000
		else
			print("unfourtanely, this product purchase has absoultely nothing to do with coins so stop. thx")
		end
	end
end
4 Likes

This did not work. Could you help me more?

2 Likes

How did you get the developer product ids? Sometimes people accidentally get the asset ID instead of the product ID

2 Likes

Nope. They are the product ID. I checked because that was my last mistake!

1 Like

And the game is releasing soon. And I do… kind of need help lol

1 Like

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