MessagingService SubscribeAsync receiving old messages

Hello! I am working on a system to display an across-server message that a donation has been purchased. The only problem is, as I test different products to make sure that the conversion from ProductId to the Price works, the SubscribeAsync is receiving old messages and the new one. Does anyone have a fix for this?

Heres the code:

local Debris = game:GetService("Debris")
local HttpService = game:GetService("HttpService")
local MarketplaceService = game:GetService("MarketplaceService")
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DonationEvent = ReplicatedStorage:WaitForChild("DonationEvent")
local template = ReplicatedStorage:WaitForChild("DonateTemp")

local idToPrice = {
	["1"] = 5,
	["2"] = 10,
	["3"] = 50,
	["4"] = 75,
	["5"] = 100
}

MarketplaceService.ProcessReceipt = function(receiptInfo)
	print("Purchased")
	local playerId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId
	local player = Players:GetNameFromUserIdAsync(playerId)
	
	local toSend = {["Player"] = player, ["Product"] = productId}
	local encoded = HttpService:JSONEncode(toSend)
	
	print("Sent at "..tostring(tick()))
	MessagingService:PublishAsync("topic", encoded)
end

MessagingService:SubscribeAsync("topic", function(data)
	print("Received")
	data = HttpService:JSONDecode(data.Data)
	local player = data["Player"]
	local product = data["Product"]
	product = idToPrice[tostring(product)]
	
	local newTemp = template:Clone()
	newTemp.Name = player
	newTemp.Text = player.." has just donated "..tostring(product).." Robux!"
	
	for i, v in pairs(Players:GetPlayers()) do
		newTemp.Parent = v.PlayerGui.MainGui.Background.DonationFeed
	end
	
	Debris:AddItem(newTemp, 15)
end)

Note: the print statements are for testing you may ignore them

Nevermind, I forgot to return in the ProcessReceipt event

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