How do I make a server message everyone sees like in TSB? (LegacyChatService)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello! I would like to achieve an effect like when a player joins the game the chat makes a message Player.Name… has arrived or Player.Name…“'s crab is calling!” like in the Strongest Battlegrounds.
  2. What is the issue? Include screenshots / videos if possible!
    How would I do this with LegacyChatService? I used ChatMakeSystemMessage but it only appears for that client and not all players can see it.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using a remote event when the player joins, firing that to all clients with the player’s name as a parameter and then making a system message in the chat.
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("ChatMakeSystemMessage", {Text = "Hello World!", Color = Color3.fromRGB(255, 255, 255)})
3 Likes

Just listen to the player added event on the client:

--Run the code inside a LocalScript under StarterPlayer.StarterPlayerScripts
game.Players.PlayerAdded:Connect(function(player)
	local text = player.Name.." joined the server!"
	local color = Color3.fromRGB(255, 255, 255)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = text, Color = color})
end)

For server side messages that can’t be picked up on the client, simply fire a remote to all the clients with the text and the color, and when they pick it up run the core function on the client.

2 Likes

.PlayerAdded runs on client???

2 Likes

For other players being added while you have loaded yes, for the same client I think it doesn’t(because the client scripts run after the player loads in).

2 Likes

So like this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local ServerMessage = RemoteEvents:WaitForChild("ServerMessage")

game.Players.PlayerAdded:Connect(function(Player)
	local text = "["..Player.Name.."]".." has arrived!"
	local color = Color3.fromRGB(255, 222, 151)
	
	ServerMessage:FireClient(Player, text, color)
end)
1 Like

Yes but for this specific case this isn’t needed(because PlayerAdded automatically replicates to the client). Also you would need to fire the remote to all players, since you’re making server announcements. So use ServerMessage:FireAllClients(text, color) instead.

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local ServerMessage = RemoteEvents:WaitForChild("ServerMessage")

game.Players.PlayerAdded:Connect(function(Player)
	local text = "["..Player.Name.."]".." has arrived!"
	local color = Color3.fromRGB(255, 222, 151)
	
	ServerMessage:FireAllClients(Player, text, color)
end)

local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local ServerMessage = RemoteEvents:WaitForChild("ServerMessage")

local StarterGui = game:GetService("StarterGui")
local success

ServerMessage.OnClientEvent:Connect(function(text, color)
	while not success do
		success = pcall(StarterGui.SetCore, StarterGui, "ChatMakeSystemMessage", {Text = text, Color = color})
		task.wait()
	end
end)
1 Like

Make sure to add success = false under the while loop, else it will only print a single message since the debounce is never disabled(or make success a local variable).

1 Like

Now it doesn’t show up in the chat bar.

1 Like

Remove the Player argument from FireAllClients

2 Likes

I understand why. FireAllClients doesn’t require a player parameter, so it errored.

1 Like

It only appears for me. Another player cannot see if I joined the message.

1 Like

Never really seen the ChatMakeSystemMessage been used in a pcall before so consider removing it or if you prefer to use a pcall write it like this: Edit: Don’t bother with a while loop

local success, result = pcall(function()
     -- Add in the logic etc.
end)
2 Likes

If I don’t use pcall it will error and I’m trying to avoid that.

Ok so here is the full script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local ServerMessage = RemoteEvents:WaitForChild("ServerMessage")

game.Players.PlayerAdded:Connect(function(Player)
	local text = "["..Player.Name.."]".." has arrived!"
	local color = Color3.fromRGB(255, 228, 157)
	
	ServerMessage:FireAllClients(text, color)
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local ServerMessage = RemoteEvents:WaitForChild("ServerMessage")

local StarterGui = game:GetService("StarterGui")

ServerMessage.OnClientEvent:Connect(function(text, color)
	local success, errormessage = pcall(function()
		StarterGui:SetCore("ChatMakeSystemMessage", {Text = text, Color = color})
	end)
	
	if success then
		print(success)
	else
		warn(errormessage)
	end
end)
1 Like

That’s probably because they join after the message is broadcasted(same reason for why your chat is empty when you join a game, despite people chatting before you joined).

Technically you can cache the past broadcasts inside replicated storage and load them from there on player join, but for this it isn’t practical because in a real world scenario the player only cares for people joining after them.

2 Likes

I made this a while back, not sure if it works anymore with the updated textchatservice, but give it a shot:

local sm = Color3.fromRGB(24, 255, 159)
local joinMessage = " has joined the game!"
local displayJoinMessage = true
local leftMessage = " has left the game!"
local displayLeaveMessage = true

local function createMessageOnClient(msg)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = msg;
		Font = Enum.Font.SourceSansBold;
		Color = sm;
		FontSize = Enum.FontSize.Size18;
	})
end

if displayJoinMessage then
	createMessageOnClient(game:GetService("Players").LocalPlayer.Name..joinMessage)
	game:GetService('Players').PlayerAdded:Connect(function(plr)
		createMessageOnClient(plr.Name..joinMessage)
	end)
end

if displayLeaveMessage then
	game:GetService('Players').PlayerRemoving:Connect(function(plr)
		createMessageOnClient(plr.Name..leftMessage)
	end)
end

And yes, the first lines of code are configurable.

This goes in StarterPlayer → StarterPlayerScripts

2 Likes

I put the local script in StarterGui. Would that work as well?

I think so, I’m not sure. If it doesn’t work in StarterGUI, try starterplayerscripts.

It works in StarterGui. It’s connected to a .PlayerAdded event on the server which fires to all clients and it displays the message.

Is it because I’m in Team Test? Because when I test it says the name of the local player has joined, but it doesn’t say Player1 joined. Just Player2.