What do you want to achieve? A developer product that when you buy it your currency increases
What is the issue? The currency does not increase, even with correct coding!
What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes. Nothing seems to work
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)
-- -- 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
-- -- 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
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
-- -- 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
if s then print("supposedly went through") return Enum.ProductPurchaseDesicion.PurchaseGranted elseif not s then warn(e) return Enum.ProductPurchaseDecision.NotProcessedYet end
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)