Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ProcessReceipt wont fire and doesnt work at all?

event.OnServerEvent:Connect(function(player,id,imageid,clothesname)
	
	local mystring = string.lower(clothesname)
	local character = player.Character
	print("test1")
	local function processreceipt(receiptInfo)
		print("test2")
		local playerProductKey = receiptInfo.PlayerId..":"..receiptInfo.ProductId
		local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if not player then
			print('not player')
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end

		if player then
			print('test3')
			if string.find(mystring,"shirt") or string.find(mystring,"suit") or string.find(mystring,"hoodie") or string.find(mystring,"sweater") then
				local shirt = character:WaitForChild("Shirt")
				if shirt then
					shirt.ShirtTemplate = ("http://www.roblox.com/asset/?id="..id)
				end
			elseif string.find(mystring,{"pants","jeans","sweatpants","shorts"}) then
				local pants = character:WaitForChild("Pants")
				if pants then
					pants.PantsTemplate = ("http://www.roblox.com/asset/?id="..id)
				end
			end
			local purchases = player:WaitForChild("leaderstats").Purchases
			purchases.Value = purchases.Value + 1
			print('test4')
			local success,errorMessage = pcall(function()
				PurchaseHistory:SetAsync(playerProductKey)
			end)
			print('test5')
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end	
	end
	MPS.ProcessReceipt = processreceipt
	print('test6')
end)

so this is my script and only print test1 and test 6 fire the processreceipt doesnt fire at all when buying the product(its not a dev product idk if i should be using processreceipt for a 3rd party sale)

1 answer

How's it supposed to fire if you are not calling it

MPS.ProcessReceipt = processreceipt -- no

In this case you are setting the function itself to the variable so MPS.ProcessReceipt is the function. You need to use brackets and since the function requires 1 argument, pass it into the brackets, so:

MPS.ProcessReceipt = processreceipt(receiptInfo)

receiptInfo should be some other variable but i can't know

5 comments

0

ty that was dumb of me but when i do that it says attempt to index nil with PlayerId

0

@jovkon123 the correct term is player.UserId.

0

well i just checked the wiki apparently it was supposed to be without the brackets cuz it assigns the function to the variable cuz of the returns but it doesnt fire when its like that

0

What's in output

0

wdym? you are telling that the function is not firing, it's because you did not use brackets, it returns the function itself if you don't use brackets, do you want to call the function in other part of the script from the table or what??

This discussion is preserved as it was. New answers, comments, and votes are closed.