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

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.

Yes, it won’t say your name. (If you try mine, it does.)

@SonicFrontiers011 mine does work with legacychatservice so give mine a go.

Erm :nerd_face: why does .PlayerAdded run on client? I thought it only ran on server. I’m going to look it up.

It does work on the client. Just try it.

That’s because Player1 loads before Player2, so they can pick up the broadcast. Player2 can’t see Player1 joining because they joined before them.

1 Like

I think I may have found an answer.

Why are you being so ignorant? Just try the script I provided.

I just did? What do you mean by that?

The script I provided works. I tested it and it worked. And you didn’t give an answer whether it did or did not.

It works. (roblox text limit i have to type longer)

Thank you, please mark my reply as the solution then. Good day.

There’s more information on this post:

Thank you to everyone who responded to this post and helped me better understand. On server, .PlayerAdded runs when any player joins the game. But on client, .PlayerAdded only runs on the client that joined. It doesn’t run for the first player because the player joins before the local script runs.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.