Messaging Service :SubscribeAsync() callback count increases each call

Hi im trying to send a message across servers with messaging service and when i call the :PublishAsync()

1st time the callback runs 1 time
2nd time it runs 2 times
3rd time it runs 3 time

and keep increasing the callback run count.

I dont know why. I havent found any fix but im using the studio to test this. so idk if that’s the problem.

One Script

MessagingService:SubscribeAsync("KILLED_ALL",function()
print("Killed")
end)

Another Script

MessagingService:PublishAsync("KILLED_ALL",info.PlayerId)

any help would be appreciated :slight_smile:

2 Likes

Are these the full scripts? If not, could you please show them?

2 Likes
--ABprice
--Ref
local MessagingService = game:GetService("MessagingService")

local KillAllProductId = 1573117560
local RevengeProductID = 1584502433

local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(info)
	local ProductID = info.ProductId
	if KillAllProductId == ProductID then
		MessagingService:PublishAsync("KILLED_ALL",info.PlayerId)
	elseif ProductID == RevengeProductID then
		MessagingService:PublishAsync("REVENGE",info.PlayerId)
	end
end

this is the publish one, other one is same

1 Like

You are not returning a ProductPurchaseDecisionEnum, returning nothing tells roblox that the purchase still has not been fulfilled. (Roblox will retry incomplete purchases)
It is also recommended to wrap network calls in pcalls as they can error

local MessagingService = game:GetService("MessagingService")

local KillAllProductId = 1573117560
local RevengeProductID = 1584502433

local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(info)
	local ProductID = info.ProductId
	local Success, Error
	if KillAllProductId == ProductID then
		Success, Error = pcall(MessagingService.PublishAsync, MessagingService, "KILLED_ALL", info.PlayerId)
	elseif ProductID == RevengeProductID then
		Success, Error = pcall(MessagingService.PublishAsync, MessagingService, "REVENGE", info.PlayerId)
	end
	if not Success then
		warn(Error)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

If you return NotProcessedYet, roblox will retry once they purchase again or rejoin. If the purchase is not completed in 3 days, roblox will automatically refund the user.
Returning PurchaseGranted tells roblox that you have fulfilled the purchase.

Highly recommend reading the documentation so you understand the behaviour of how roblox handles purchases MarketplaceService | Documentation - Roblox Creator Hub

2 Likes

Thanks so much! been trying to find a solution for hours xD

3 Likes

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