Sometimes (rarely) I get the error: MessagingService: Service disconnected

This has happened a few times when I play my project in development, in Studio: I get this error:

MessagingService: Service disconnected

But this occurs many lines after the service has been started.
For example, in the first lines of my script I have:

local MessagingService = game:GetService("MessagingService")

And at the end of the script, I have:

MessagingService:SubscribeAsync('MyMsg', function(Msg)

and here I (rarely) get this error.

But if I run the project again, no errors.

What could it be?
Any way to avoid this?

1 Like

To avoid this error:

repeat
	local Success, Errormessage = pcall(function()
		MessagingService:SubscribeAsync('MyMsg', function(Msg)
             ...
		end)
	end)

	if not Success then
		print("MessagingService:SubscribeAsync. Retrying")
		warn(Errormessage)
		wait(1)
	end	
until Success
3 Likes