Create Purchase History system

  1. What do you want to achieve?
    I would like to develop a “purchase history” system that stores information about products players have purchased. This information would be saved, ensuring that even when the player leaves the game, everything will be saved and ready to be accessed when they return.

  2. What is the issue?
    I do not know where to start.

  3. What solutions have you tried so far?
    I did some research, but didn’t find anything on the subject.

Example of what I’m trying to do:

Quick answer, Datastores.
You could mock up a quite system that uses their userid for the Datastore as that is unique to them, for example you could make a custom ProcessReceipt function to handle sales in a secure way, for example.

Then you would make a system that uses Remote Function to grab it from the server and return it to the client with all the Players Purchases and then load them in automatically as it all saves in a table.

local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local ProductData = {}

MarketplaceService.ProcessReceipt = function (receiptInfo)
	if receiptInfo then
		local Player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
		local Data = Datastore:GetAsync(Player.UserId)
		local Product = MarketplaceService:GetProductInfo(receiptInfo.ProductId)
		
		print('Loading order data...')
		if not Player then
			print('Failed to find player inside of game, order not processed.')
			return Enum.ProductPurchaseDecision.NotProcessedYet
		else
			local val 
			
			for i, v in pairs(ProductData) do
				val = i
			end
			
			local NewData = {
				[val] = {
					['Username'] = Player.Name,
					['UserId'] = Player.UserId,
					['Receipt'] = receiptInfo.ProductId,
					['Product'] = Product
				}
			}

			table.insert(ProductData, NewData)
			
			local Success, Response = pcall(function()
				Datastore:SetAsync(Player.UserId, ProductData)
			end)
			
			if Success then
				print('Succesfully returned order.')
				return Enum.ProductPurchaseDecision.PurchaseGranted
			else
				warn(Response)
			end
		end
	end
end