Help with Sending A table trough messaging service

When I try to send a table with Messaging Service, the server returns me with this error:

The error happens into the lobby side of the game, the message is sent from another place which is the main game

This is the script for the main game

local dataStore = game:GetService("DataStoreService")
local messagingService = game:GetService("MessagingService")
local httpService = game:GetService("HttpService")
local ownerFound = false

local JobId = game.JobId
local owner 

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if ownerFound == false then
			ownerFound = true
			
			local LobbyData = {

				LobbyName = player.Name .. "'s Lobby",
				LobbyJobId = JobId,
				LobbyOwner = player.Name

			}
			
			--local encodedData = httpService:JSONEncode(LobbyData)
			
			messagingService:PublishAsync("GlobalAnnouncement", LobbyData)
			print(encodedData)
			print("Sent")
		end
	end)
end)

and this is the script for the Lobby Side

function callbackFunction(serviceData)
	 local decodedData = httpService:JSONDecode(serviceData.data)
	print("Decoded Data")

	local newLobby = Instance.new("StringValue", TeamsFolder)
	newLobby.Name = decodedData.LobbyName

	local owner = Instance.new("IntValue", newLobby)
	owner.Name = "Owner"
	owner.Value = decodedData.Owner

	local LobbyJobId = Instance.new("IntValue", newLobby)
	LobbyJobId.Name = "GameJobId"
	LobbyJobId.Value = decodedData.LobbyJobId
end

In the first script you are not encoding the data, in the second one you are decoding serviceData.data, you should change that to only serviceData.

now it returns me with this error, If Im not mistaken the data that is gonna be sent trough messaging service will return a JSON format which I do not know how to convert

Are you encoding the data and sending that or are you sending raw data?

I think by publishing the message, the service will automatically encode the data

(from what I read about)

Are you using SubscribeAsync to receive data?
Also im not sure if you were using this but here this might help:

1 Like

Yes I also used that lol thats were I found some info about sending tables into messaging service and yes I forgot to paste the part where I use Subscribe Async lol

Also its fixed now tnx for the help

(also the solution was doing this:
local decodedData = httpService:JSONDecode(ServiceData.Data)

I didnt captitalize d Into Data llol

2 Likes