Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is the Messaging Service not transferring a string?

So I am trying to make it so I can call a bindable function through the command line, and be able to have a message replicate to the clients' GUI. When I pass the string "test" through the command line as a parameter for the :Invoke() method of my bindable function, it goes through to the function I have hooked up to the bindable function callback, but it does not go through the :PublishAsync() method as a string. The value it returns is a table, and when I tested for the amount of values in the table, it returned 0 values. I am asking to figure out how to pass a string properly, and possibly why it did not work the way I did it. Thanks.

local msgServ = game:GetService("MessagingService")
local msgCall = game.ReplicatedStorage:WaitForChild("MsgCall")
local msgEv = game.ReplicatedStorage:WaitForChild("REMMessageEV")

msgServ:SubscribeAsync("GlobalMessage", function(msg)
	msgEv:FireAllClients(msg)
	print(msg)
end)


function msgRec(msg)
	print(msg)
	print("Recieved")
	msgServ:PublishAsync("GlobalMessage", msg)
end



msgCall.OnInvoke = msgRec

--[[

Returns:

S:  test
S:  Recieved
S:  table: 0xaf110b504d891221

]]

1 answer

Through extra research I figured out the issue.

I did not realize that the service sends the data in a table with the data sent as a value of a Data key.

Note: HttpService is not required

local msgServ = game:GetService("MessagingService")
local hpServ = game:GetService("HttpService")
local msgCall = game.ReplicatedStorage:WaitForChild("MsgCall")
local msgEv = game.ReplicatedStorage:WaitForChild("REMMessageEV")

msgServ:SubscribeAsync("GlobalMessage", function(data)
	local tCheck = hpServ:JSONEncode(data)
	msgEv:FireAllClients(data.Data)
	print(data.Data)
	print(tCheck)
end)


function msgRec(msg)
	print(msg)
	print("Recieved")
	msgServ:PublishAsync("GlobalMessage", msg)
end



msgCall.OnInvoke = msgRec

This discussion is preserved as it was. New answers, comments, and votes are closed.