Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the Messaging Service not transferring a string?

Asked by
0xSRK6 0
3 years ago

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

Log in to vote
0
Answered by
0xSRK6 0
3 years ago

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

Ad

Answer this question