local function a(a)local z=a.PlayerId..("\095"..a.PurchaseId)local d=false local m,Q=pcall(function()d=purchaseHistoryStore:GetAsync(z)end)if m and d then return Enum.ProductPurchaseDecision.PurchaseGranted end local E=Players:GetPlayerByUserId(a.PlayerId)if not E then return Enum.ProductPurchaseDecision.NotProcessedYet end local W=_G.HandlePurchase local P,X=pcall(W,a,a.PlayerId)if not P or not X then warn("\069\114\114\111\114 \111\099\099\117\114\114\101\100 \119\104\105\108\101 \112\114\111\099\101\115\115\105\110\103 \097 \112\114\111\100\117\099\116 \112\117\114\099\104\097\115\101")print("\n\080\114\111\100\117\099\116\073\100\058",a.ProductId)print("\n\080\108\097\121\101\114\058",E)_G.FinishedPurchase(a.PlayerId,0,false)return Enum.ProductPurchaseDecision.NotProcessedYet end local v,L=pcall(function()purchaseHistoryStore:SetAsync(z,true)end)if not v then error("\067\097\110\110\111\116 \115\097\118\101 \112\117\114\099\104\097\115\101 \100\097\116\097\058 "..L)end return Enum.ProductPurchaseDecision.PurchaseGranted end

local function processReceipt(receiptInfo)
 
	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
 
	-- Find the player who made the purchase in the server
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	-- Look up handler function from 'productFunctions' table above
    local handler =_G.HandlePurchase
 
	-- Call the handler function and catch any errors
    local success, result = pcall(handler, receiptInfo, receiptInfo.PlayerId)
	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
        print("\nPlayer:", player)
        
        _G.FinishedPurchase(receiptInfo.PlayerId,0,false)
        
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
 
	-- Record transaction in data store so it isn't granted again
	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end
 
	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
 