I am not sure but I think publishasync sends information to all other scripts in the other servers not in the one you are in. If you want to transfer any data threw global scripts or local scripts, use _G.
EDIT: NVM it works in the server. I tested out the script. Here is the one I did.
playersReady = {}
shouldReply = true
messagingService = game:GetService("MessagingService")
local Isloaded = false
coroutine.wrap(function()
messagingService:SubscribeAsync("CompQueue", function(msg)
if string.find(tostring(msg.Data), "905829288") then
table.insert(playersReady, string.sub(msg.Data, 1, -10))
elseif string.find(tostring(msg.Data), "914153215") then
table.remove(playersReady, table.find(playersReady, string.sub(msg.Data, 1, -10)))
else
print("error")
end
game.ReplicatedStorage["Total Players Ready"]:FireAllClients(playersReady)
end)
messagingService:SubscribeAsync("GetExternalPlayersReady", function()
if shouldReply == true then
messagingService:PublishAsync("ExternalPlayersReady", playersReady)
end
end)
messagingService:SubscribeAsync("ExternalPlayersReady", function(msg)
print(msg.Data)
end)
Isloaded = true
end)()
game.Players.PlayerRemoving:Connect(function(playerLeaving)
if table.find(playersReady, tostring(playerLeaving)) then
messagingService:PublishAsync("CompQueue", tostring(playerLeaving).."914153215")
end
end)
game.Players.PlayerAdded:Connect(function()
repeat wait() until Isloaded
if #game.Players:GetChildren() == 1 then
messagingService:PublishAsync("GetExternalPlayersReady","")
end
end)
game.ReplicatedStorage["Ready Up"].OnServerEvent:Connect(function(playerName, ready)
game.ReplicatedStorage["Ready Up"]:FireClient(playerName, ready)
if ready == true then
messagingService:PublishAsync("CompQueue", tostring(playerName).."905829288")
else
messagingService:PublishAsync("CompQueue", tostring(playerName).."914153215")
end
end)
The problem here is that the OnPlayerAdded is done first before the SubscribeAsync has loaded.
I changed it so it could wait until the SubscribeAsync gets loaded.
As the table index should get printed as the data.
EDIT: I had to remove an argument as it was unneeded. Try again now.
what do you mean a studio bug? you forgot to right “Get” when you were publishing async here.
messagingService:SubscribeAsync("GetExternalPlayersReady", function()
if shouldReply == true then
messagingService:PublishAsync("ExternalPlayersReady", playersReady)
Oh, right.
I completely forgot it wouldn’t load in time for playerjoined, I feel so stupid now.
I’m about to go to sleep so I’ll set this as the solution if it works when I wake up.
The one without the get was sending the information back, I probably should’ve named it something better.
By studio bug I mean when Roblox Studio just doesn’t do what it should, but I think I was just stupid and put things in the wrong order.
Please solution the answer as to close the title for others.
Also, @0k_Jackk the GetExternalPlayersReady and ExternalPlayersReady are to different topics for the Subscribe Service. @BriefYayyayyay has made for both a SubscribeAsync functions so both topics are different.