So if i send a message, it ends on the same server where the PublishAsync was on, Does anyone know how to fix it?, this is my code
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local HTTPS = game:GetService("HttpService")
local MessageTopic = "Cross-Messages"
local JobId = game.JobId
print(JobId)
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Player:WaitForChild("SendOutsideMessages").Value == true then
local EditedMessage = "{Not in server} ["..Player.Name.."]: "..Message.."["..JobId.."]"
MessagingService:PublishAsync(MessageTopic, EditedMessage)
end
end)
end)
MessagingService:SubscribeAsync(MessageTopic, function(Message)
local Remote = game:GetService("ReplicatedStorage").ServerActions.Message.CastToPlayer
if Message.Data:match(JobId) then
elseif not Message.Data:match(JobId) then
Remote:FireAllClients(Message.Data)
end
end)
The jobid checking only works in studio not in the real game
This is intentional. The message is supposed to get to the same server that called it. If your trying to prevent this for whatever reason, you can pass the JobId in a table and return if the server’s JobId is the same.
Could you modify the script and reply to me back? I don’t really know how you mean works
(Edit : it kinda works but makes an error unable to cast ray here is the new code i used)
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local MessageTopic = "Cross-Messages"
local FireCounter = 0
wait(0.5)
local JobId = game.JobId
print(JobId)
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Player:WaitForChild("SendOutsideMessages").Value == true then
local EditedMessage = "[🌐] ["..Player.Name.."]: "..Message
local ToSend = {ChatString = EditedMessage, J_Id = JobId}
MessagingService:PublishAsync(MessageTopic, ToSend)
end
end)
end)
MessagingService:SubscribeAsync(MessageTopic, function(Message)
local Remote = game:GetService("ReplicatedStorage").ServerActions.Message.CastToPlayer
if game.JobId ~= Message.Data.J_Id then
Remote:FireClient(Message.Data.ChatString)
else
print("SubscribeAsync Fired ("..FireCounter..") At same server")
FireCounter += 1
end
end)