Sending multiple messages with Message Service

Every time I try to send the second message in the parameter, it comes out nil on the receiving end:

Sending the message:

MessageService:PublishAsync("BattleServer", "Test", "TestTwo")

Receiving the message:

MessageService:SubscribeAsync("BattleServer",function(MessageOne, MessageTwo)
 print(MessageOne.Data) -- Prints "Test"
 print(MessageTwo.Data) -- Prints "Nill"
end)

Would it be better to combine the two messages as one string, and then once we receive the message, split it with a specific character inside the string?

("Test,TestTwo")

-- Then Split the string when finding ","

("Test".."TestTwo")

It’s the only other workaround I can find…

You can try sending it in a table, like this:

MessageService:PublishAsync("BattleServer", {"Test", "TestTwo"})

MessageService:SubscribeAsync("BattleServer",function(Messages)
Messages = Messages.Data
 print(Messages[1])
 print(Messages[2])
end)
11 Likes

It worked, thank you very much!

3 Likes