Messaging Service Not Sending Data

hi, I’m making a system where if there is a private server, then it would send some data, to create a private server list, but its not sending any data over. When i play in the roblox client it just says nil and when i sent the data over and i printed the index’s of the table it returns 0.

code -

local module = {}

local MessagingSerivce = game:GetService("MessagingService")
local ReplicatedStoarge = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local ServerFolder = ReplicatedStoarge.Servers
local CreateServerGui = ReplicatedStoarge.RoomSystem.CreateServerGui

function module.SubscribeAllServers()
	print("Subscribed all serers")
	MessagingSerivce:SubscribeAsync("ServerList", function(data)
		print(data[1])
		data = data.Data
		print(data[1], data[2], data[3])

		if data.PrivateServerId ~= "" then
			print("Making Ui", data)
			print("Making Ui")

			CreateServerGui:FireAllClients(data)
			task.wait(5)
		end
	end)
end

function module.PublishServers()
	print("Publishing if privite")
	while game.PrivateServerId ~= "" do
		print("Game is pritive")
		local PlayersInServers = {}
		for i,v in Players:GetPlayers() do
			table.insert(PlayersInServers, v.UserId)
		end
		local data = {
			 PlayersInServers;
			 game:GetService("ServerStorage"):GetAttribute("ServerName");
			 game.PrivateServerId;
			 "hello"
			
		}
		MessagingSerivce:PublishAsync("ServerList", data)
		print(#data)
		print("rolling over")
		task.wait(5)
	end
end

return module

thank you!

just gonna bump this I need this fix soon

Heyo, Could you send the output of your console? just trying to understand this, why not just print(data) itself instead of doing data[1,2,3]

when i do that it returns the table id like table: 0xq836hfu like that type of code

Oh you’re testing in an actual Roblox client forgot, do a for loop

for i, value in data do
 print(i, value)
end

You can also send over data like this

local data = {
 PlayersInServer = PlayersInServers,
 ServerName = game:GetService("ServerStorage"):GetAttribute("ServerName"),
 ServerId = game.PrivateServerId,
 text = "hello"
}

Then you can reference it by doing data.ServerId instead of data[3], I prefer doing it this way but everyone has their own preference.

i did have it like that way but i tested the other way bu thank you anywway

so i tested it and this is he output
image
but it should print out all of these values

Okay, so which part were you looking to receive? What is that nil? it looks like it could be the ServerName?

so idk know why but it works now, and the nil is because i forgot to set the attribute. thank you for your help anyway

You’re welcome! Best of luck with your project!

1 Like