MessagingService table output?

Hello! I just got into the BETA program and trying out the MessagingService.

After some time learning about it, I tried to make a simple thing i thought

I made so when I say “/officialshow NOTE_HERE” it publishes data to all of the servers so they can join my current server.

PublishAsync
if string.sub(msg, 1, 14) == "/officialshow " then
			
		MessagingService:PublishAsync("OfficialShow", string.sub(source, 15), player.Name, player.UserId, game.JobId)
				
end

After that I made a function that handles all of the GUI’s in the other servers when it Subscribes.

MessagingService:SubscribeAsync("OfficialShow", OfficialShow)

OfficialShow Function
function OfficialShow()
	
	local text, presenter, num, instanceId = unpack(OfficialShow)
	
	local Gui = game.ReplicatedStorage:WaitForChild("OfficialShowGui"):WaitForChild("MainFrame")
	
	Gui.ProfilePicBackground.ProfilePic.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. tonumber(num) .. "&width=420&height=420&format=png"
	Gui.PresenterName.Text = tostring(presenter)
	Gui.PresenterText.Text = tostring(text)
	
	game.ReplicatedStorage:WaitForChild("OfficialShowGui").id.Value = instanceId
	
game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("MessagingService"):FireAllClients("OfficialShow")
	
end

I tried to make it unpack but I got no idea what to unpack, I know it has to be an array.

I hope someone can help! :pray:

1 Like

You don’t have to unpack anything. The arguments are passed as a vararg, so you just need to change your OfficialShow function declaration to take a vararg, and then use it.

local function OfficialShow(...)
    local text, presenter, num, instanceId = ...
    --rest of the code
end

@Amiaa16 Now this happened:

image

Oh sorry my bad, I assumed it would just spit the data you input as a vararg.
Try this:

local function OfficialShow(data)
    local text, presenter, num, instanceId = unpack(data)
    --rest
end

Everything comes out as nil, here’s what I did:

local function OfficialShow(data)
	
    local text, presenter, num, instanceId = unpack(data)
    
	local Gui = game.ReplicatedStorage:WaitForChild("OfficialShowGui"):WaitForChild("MainFrame")
	
	--Gui.ProfilePicBackground.ProfilePic.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. tonumber(num) .. "&width=420&height=420&format=png"
	Gui.PresenterName.Text = tostring(presenter)
	Gui.PresenterText.Text = tostring(text)
	
	game.ReplicatedStorage:WaitForChild("OfficialShowGui").id.Value = instanceId
	
	game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("MessagingService"):FireAllClients("OfficialShow")
	
	print("Official Show Gui Fired!")
	
end
Player Chatted Publish

game.Players.PlayerAdded:connect(function(player)

if player.Name == "Danii_ox" then
	
	player.Chatted:connect(function(msg)
		
		local source = msg
		msg = string.lower(msg)
	
		if string.sub(msg, 1, 14) == "/officialshow " then
		
			MessagingService:PublishAsync("OfficialShow", string.sub(source, 15), player.Name, player.UserId, game.JobId)
			print("Official Show Message Detected!")
			
		end
			
	end)
	
end

end)

The table it gives you is a dictionary with Data and Sent. What you’re looking for is data.Data. Try unpacking that.

1 Like

Take a look at this

This should help you solve the issue.

1 Like

I found the answer here, Messaging Service - #6 by RuizuKun_Dev :newspaper::white_check_mark:

Great, can you please mark your post as solved?

1 Like