MessagingService unable to send dictionary

Hey there, I’m attempting to create a lobby menu where you can join players before teleporting to another place together, using MessagingService. I’ve seen other games have such a feature where the name, image, and total amount of players are displayed at the same time; after watching several tutorials I see that most have the message.Data as a dictionary, however when I set it to a dictionary it returns the error:
“MessagingService:PublishAsync(): Cannot publish Dictionary, can only accept valid UTF-8 characters.”

This is my code, unabashedly ripped from DevWiki:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MessagingService = game:GetService("MessagingService")
local CreateLobbyEvent = ReplicatedStorage.CreateLobby

CreateLobbyEvent.OnServerEvent:Connect(function(player, what, place)
	if what == "create" then
		local publishSuccess, publishResult = pcall(function()
			local message = {
				host = player,
				placeToGo = place
			}
			MessagingService:PublishAsync("LobbyCreated", message)
		end)
		if not publishSuccess then
			print(publishResult)
		end
	end
end)

Not sure if I’m missing something glaringly obvious, but even after unwrapping the above code from pcalls the same error is happening. Here is youtube link where they use a dictionary in the message data: -M_HwlQ5xmE

The only solution I can think of is to simply have many different channels for each variable (playeradding, playerremoving, lobbycreation, lobbyabandon, etc etc etc)

Any help is appreciated. Cheers!

You could use HTTPService:JSONEncode() to turn the dictionary into a JSON string. Once the message is received, you could do HTTPService:JSONDecode()

1 Like

Thank you very much! I hadn’t heard of this service before, but it seems to be exactly what I was looking for!

1 Like