You can write your topic however you want, but you need to answer these questions:
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.
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.
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)})
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.
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).
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)
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.
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)
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).
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)
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)
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.
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.