How would I make it so that once a Developer Product is purchased, it shows a message in the chat

I want it so that lets say “slayerguy906” bought a developer product, how would I make it so that it says in the chat “slayerguy906 has purchased (item name)”?

1 Like

You would use MarketPlaceService.PromptPurchaseFinished to detect when a player buys the product, and then you send a message in chat using StarterGui:SetCore(“ChatSystemMakeMessage”)

1 Like

Adding to what @ValiantWind has said above, I will now send a full detailed code.
Here:

--Server
local market = game:GetService("MarketplaceService")
local replicated = game:GetService("ReplicatedStorage")

local remote = replicated:FindFirstChild("MessageOnChat")
local products = {1292099091,000000}


market.ProcessReceipt = function(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if receiptInfo.ProductId == products[1] then
		local success,result = pcall(function()
			return market:GetProductInfo(products[1],Enum.InfoType.Product)
		end)
		if success then
			remote:FireAllClients(player.Name,result.Name)
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end


--Client
local replicated = game:GetService("ReplicatedStorage")
local gui = game:GetService("StarterGui")

local remote = replicated:WaitForChild("MessageOnChat")

remote.OnClientEvent:Connect(function(Player,Product)
	gui:SetCore("ChatMakeSystemMessage",{
		Text = Player.." has purchased this product: "..Product;
		Color = Color3.fromRGB(255, 170, 0)
	})
end)

4 Likes

I noticed that with that code you could only do one ID, therefore I changed it to make it handle multiple :^).

Also Roblox changed the message system, so in case anyone is looking for an updated version:

Server:

local MarketPlaceService = game:GetService("MarketplaceService")

local Replicated_Storage = game:GetService("ReplicatedStorage")
local Events = Replicated_Storage:WaitForChild("Events")

local Donation_Message_Event = Events:WaitForChild("Donation_Message")

local Donation_IDs = {

	1111111111,
	1111111111,
	1111111111,
	1111111111,
	1111111111,

}

MarketPlaceService.ProcessReceipt = function(receiptInfo)

	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	local ID = nil
	
	for _, Donation_ID in pairs(Donation_IDs) do
		
		if Donation_ID == receiptInfo.ProductId then
			
			ID = Donation_ID
			break
			
		end
		
	end
	
	if receiptInfo.ProductId == ID then
		local success,result = pcall(function()
			return MarketPlaceService:GetProductInfo(ID,Enum.InfoType.Product)
		end)
		if success then
			Donation_Message_Event:FireAllClients(player.Name,result.Name)
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
end

Client:

local Replicated_Storage = game:GetService("ReplicatedStorage")

local Events = Replicated_Storage:WaitForChild("Events")
local Donation_Message_Event = Events:WaitForChild("Donation_Message")

local TextChatService = game:GetService("TextChatService")

Donation_Message_Event.OnClientEvent:Connect(function(Player,Product)
	TextChatService.TextChannels.RBXSystem:DisplaySystemMessage(`<font  size='{22}' color='{"#00ff2a"}'>` .. Player .. ` has bought: ` ..Product .. `</font>`)
end)