How do I make a message that is sent in the chat so that every player from every server can see it?

I am trying to make it so that when a user touches a part, a global message goes into the chat that shows in every server. It works, but only in the server that the player touched the part in and not every server that is running on the game. I have tried using game.StarterGui:SetCore(“ChatMakeSystemMessage”), and it does display in the chat but again, not to every server. I have 0 idea how I would achieve this.

--Client Script
local cs = game:GetService("CollectionService")
local rs = game:GetService("ReplicatedStorage")

local delay = 1
local sendMessage = true

for _, v in cs:GetTagged("Completion") do
    v.Touched:Connect(function(hit)
        local hum = hit.Parent:FindFirstChild("Humanoid")
        local char = hum.Parent
        
        local message = char.Name .. " has completed the " .. v.Name
        
        if hum then
            if sendMessage == true then
                
                local chatMessage = game.StarterGui:SetCore("ChatMakeSystemMessage",
                    {
                        Text = "[GLOBAL]: " .. message,
                        Color = Color3.fromRGB(95, 0, 173),
                        Font = Enum.Font.SourceSansBold,
                        TextSize = 18
                    }
                )
                
                rs.SendMessage:FireServer(chatMessage)
                sendMessage = false
                task.wait(delay)
                sendMessage = true
            end
        end
    end)
end



--Server Script
local ms = game:GetService("MessagingService")
local cs = game:GetService("CollectionService")
local rs = game:GetService("ReplicatedStorage")

rs.SendMessage.OnServerEvent:Connect(function(player, globalMessage)
    ms:SubscribeAsync("Announcement", function(msg)
        msg.Data = globalMessage
    end)
    
    ms:PublishAsync("Announcement", globalMessage)
end)

As you can see, I used MessagingService. The data of the message is equal to to the message that is actually sent in chat, and I passed this variable through a SendMessage remote event that I created. That’s what I’m confused on, since the data is equal to the chat message. It might be because the data is equal to the message in a server script, but the actual message is in a local script. But SetCore() can only be used in local script, since I get an error every time I try it in a server script. If you have any questions about my script I’ll answer them.

1 Like

I would Reccomend firing to all Clients rather than the Server, this means you should have the event on the Client and Fire on the Server using FireAllClients, this is so everybody in the Server can see it on their screen, or chat.

Also, this is isnt MessagingService, Messaging Service allows you to fire/communicate to all Servers Subscribed using SubscribeAsync and PublishAsync

Move the :SubscribeAsync outside of the function. Every server has to already be subscribed for them to see the message. Once you do that, I believe your script is ready to work fine.

alright i have this now and it is still doing the same thing. im new to scripting so if i dont get anything then sorry

--Server Script
local ms = game:GetService("MessagingService")
local cs = game:GetService("CollectionService")
local rs = game:GetService("ReplicatedStorage")

ms:SubscribeAsync("Announcement", function(msg)
	rs.SendMessage.OnServerEvent:Connect(function(player, globalMessage)
		msg.Data = globalMessage
		
		ms:PublishAsync("Announcement", globalMessage)
		rs.SendMessage:FireAllClients(globalMessage)
	end)
end)	

--Client Script
--Client Script
local cs = game:GetService("CollectionService")
local rs = game:GetService("ReplicatedStorage")

local delay = 1
local sendMessage = true

for _, v in cs:GetTagged("Completion") do
	v.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local char = hum.Parent

		local message = char.Name .. " has completed the " .. v.Name

		if hum then
			if sendMessage == true then

				local chatMessage = game.StarterGui:SetCore("ChatMakeSystemMessage",
					{
						Text = "[GLOBAL]: " .. message,
						Color = Color3.fromRGB(95, 0, 173),
						Font = Enum.Font.SourceSansBold,
						TextSize = 18
					}
				)
				
				sendMessage = false
				task.wait(delay)
				sendMessage = true
			end
		end
	end)
end
1 Like

what’s the difference between replicating to the server and replicating to all clients?

ok idk if anyone is still reading this but i found out about MemoryStoreService. does anyone think i can use that for this situation?

1 Like