DevProduct Script Not Working

Hey, I’m making a currency devproduct script, but the serverscript isn’t working.

AlvinBlox Tutorial I followed: https://www.youtube.com/watch?v=h92s4Xn26oc

This is the local script which works fine

local MarketplaceService = game:GetService("MarketplaceService")

local player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()

MarketplaceService:PromptProductPurchase(player, 1035581598)

print("sent the request to marketplace")

end)

This is the serverscript (if a put a print anywhere below the function it won’t print)

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
print("top")
local currencyName = "Gems"

local PreviousPurchases = DataStoreService:GetDataStore("PreviousPurchases")
print("got the previous purchases")
local FIFTEEN_GEMS = 1035581598
local EIGHTY_GEMS = 1035586681
local ONESEVENTY_GEMS = 1035587411
local THREESIXTY_GEMS = 1035588353
local NINEFIFTY_GEMS = 1035590075
local TWOTHOUSAND_GEMS = 1035590730
local BUY_PREMIUM = 1055143443
print("got all of the id's")
MarketplaceService.ProcessReceipt = function(receipt)
	local ID = receipt.PlayerId.."-"..receipt.PurchaseId
	print("got the ID")
	local succes = nil
	
	pcall(function()
		success = PreviousPurchases:GetAsync(ID)
		print("success")
	end)
	
	if success then
		print("purchase has been granted")
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end	
	
	local player = game.Players:GetPlayerByUserId(receipt.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	else
		
		if receipt.ProductID == FIFTEEN_GEMS then
			print("adding fifteen gems")
			player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 15
		end
		
		if receipt.ProductID == EIGHTY_GEMS then
			player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 80
		end
		
		if receipt.ProductID == ONESEVENTY_GEMS then
			player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 170
		end
		
		if receipt.ProductID == THREESIXTY_GEMS then
			player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 360
		end
		
		if receipt.ProductID == NINEFIFTY_GEMS then
			player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 950
		end
		
		if receipt.ProductID == TWOTHOUSAND_GEMS then
			player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 2000
		end
		
		if receipt.ProductID == BUY_PREMIUM then
			player.PremiumPass.Owned.Value = true
		end
		
		pcall(function()
			PreviousPurchases:SetAsync(ID,true)
			end)
			return Enum.ProductPurchaseDecision.PurchaseGranted
		
	end
end

Thanks

Is your script enabled?

Do you have MarketplaceService.ProcessReceipt in any other scripts at all? Remember that it can only be defined one time in one script.

Does “got the ID” print out at all?

1 Like

Oh, yeah I have this script. So I need to add this to my other script and combine them as one?

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1055143443 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.PremiumPass.Owned.Value = true
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

Yes, MarketplaceService.ProcessReceipt can only be defined in one place (this is why it’s not working), so you need to put that code in with your other code (I hope AlvinBlox covered this).

1 Like

More of the code is working now, but nothing runs after this pcall

pcall(function()
		success = PreviousPurchases:GetAsync(ID)
		print(success)
	end)

success prints as nil

Be sure to print out any errors that you have when using pcall, as pcall doesn’t print errors out on its own.

local result

local success, errormessage = pcall(function()
	result = PreviousPurchases:GetAsync(ID)
	print(result)
end)
if not success then
  print(errormessage)
end

I’m not sure since I don’t know whether there is an error, but it could just be that the data store is returning nil.

1 Like