Problem with currency for developer product

I have problem with developer products. It is not giving a player currency or only one button works.

local DataStoreService = game:GetService("DataStoreService")
local LeaderstatDataStore = DataStoreService:GetDataStore('SaveValue')

local DeveloperProductID = 1570317441 -- Change this ID with your Developer Product ID

game.Players.PlayerAdded:Connect(function(player)
	local Leaderstat = player.leaderstats.hiddenfolder.Coins

	local LeaderstatKey = player.UserId .. "_Coins"
	local success, savedValue = pcall(function()
		return LeaderstatDataStore:GetAsync(LeaderstatKey)
	end)
	if success and savedValue then
		Leaderstat.Value = savedValue
	end

	local Purchased = false

	game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
		if receiptInfo.PlayerId == player.UserId and receiptInfo.ProductId == DeveloperProductID and not Purchased then
			Purchased = true

			Leaderstat.Value += 100

			local Success, error = pcall(function()
				LeaderstatDataStore:SetAsync(LeaderstatKey, Leaderstat.Value)
			end)
			if not Success then
				warn("Failed to save leaderstat data:", error)
			end
			Purchased = false
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end)

This callback [ProcessReceipt] should be set once and only once by a single Script. If you’re selling multiple products in your experience, this callback should handle receipts for all of them.

Put ProcessReceipt outside of game.Players.PlayerAdded, as every time a player join, you’re setting the callback for .ProcessReceipt to another function, which you are not allowed to do. You’ll have to fetch the player from the playerId under receptinfo.

Look at this for more info: MarketplaceService | Documentation - Roblox Creator Hub

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.