How to send server message using new TextChatService?

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to create a communication line with RemoteEvents and clients. Id like to know how id go about sending a message to all players using the new chat service; such as whenever a player joins.
4 Likes

This should help: In-Experience Text Chat | Roblox Creator Documentation

2 Likes

I couldn’t find anything specifically on how to send a custom chat. Should I have a script in ServerScriptService that monitors players joining? And how would I communicate from a normal script to the Localscript that receives and displays the message to all clients?

To send a message to all players using the new chat service in Roblox, you can use a combination of RemoteEvents and the Chat service API.

First, you will need to create a RemoteEvent on the server to handle the communication. You can do this using the following code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NewPlayerEvent = Instance.new("RemoteEvent")
NewPlayerEvent.Name = "NewPlayerEvent"
NewPlayerEvent.Parent = ReplicatedStorage

This will create a new RemoteEvent called “NewPlayerEvent” in ReplicatedStorage. You can then use this event to trigger a message to all players whenever a new player joins the game.

Next, you will need to create a script that listens for the “NewPlayerEvent” and sends a message to all players. You can do this using the following code:

local Players = game:GetService("Players")
local ChatService = game:GetService("Chat")

local function OnNewPlayer()
    ChatService:SayAllChannel("A new player has joined the game!")
end

game.ReplicatedStorage.NewPlayerEvent.OnServerEvent:Connect(OnNewPlayer)

This script will listen for the “NewPlayerEvent” and when it is triggered, it will send a message to all players using the Chat service API. The message in this example is “A new player has joined the game!”, but you can customize this message to your liking.

Finally, you will need to trigger the “NewPlayerEvent” whenever a new player joins the game. You can do this by adding the following code to your game’s “StarterPlayerScripts” folder:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function OnPlayerAdded(player)
    ReplicatedStorage.NewPlayerEvent:FireAllClients()
end

Players.PlayerAdded:Connect(OnPlayerAdded)

This script will trigger the “NewPlayerEvent” whenever a new player joins the game, which will in turn send a message to all players using the Chat service API.

1 Like

Not showing any message in chat. Is the script in StarterPlayerScripts supposed to be local?

You actually have to dig through the docs for this because how you do it is pretty funny.

If you are using new TextChatService GUI then It should look like this
image

local Service = game:GetService("TextChatService")

Service.TextChannels.RBXSystem:DisplaySystemMessage("Text")

Roblox made devs do through there docs for this. Forum that recently popped up that “CoreGUI” doesnt work anymore with new TextChatService, This is the Forum

It supports Rich Text with mimics HTML (Client & Server)

If this works. Please Solution :smiley:

12 Likes

I put this code in a Localscipt in StarterPlayerScripts and it still won’t show in the chat

The “TextChatService Gui” gets created when your “Character” gets created

You would need to put it into your “StarterCharacterScripts”

1 Like

If you want you can also do it where if you want a player to join you can do a RemoteEvent and Fire it to the client

i tried using this, but nothing shows in chat.

local function OnPlayerAdded(player)

local Service = game:GetService("TextChatService")

Service.TextChannels.RBXSystem:DisplaySystemMessage("Text")

end

Players.PlayerAdded:Connect(OnPlayerAdded)

Players.PlayerAdded wont be activated in a StarterCharacter StarterPlayers

how should I have a normal script communicate with a Localscript to show messages. (player joins game, communicates to a localscript which in turn shows it as a system message in player chat)

Local:

local Message = game:GetService('ReplicatedStorage').Message

Message.OnClientEvent:Connect(function(Player)
	
	local TextChatService = game:GetService("TextChatService")
	local TextChannels = TextChatService:WaitForChild("TextChannels")

	print("Heyo!")

	TextChannels.RBXSystem:DisplaySystemMessage("<font color = \"rgb(255,0,0)\">" .. Player.Name .. "</font> Joined!")
	
end)

Server:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)

	game.ReplicatedStorage.Message:FireClient(Player)


end)
11 Likes

got this in Output
Workspace.Virtecc.LocalScript:11: attempt to index nil with 'Name'

also, one last question, is keeping the Localscript in StarterCharacterScripts the right spot?

Thanks for your and everyone else’s help.

Yes it is.
BTW Here is fixed script
Server:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	
	print(Player.Name)
	game.ReplicatedStorage:WaitForChild("Message"):FireAllClients(Player)


end)

| Please Solution |

11 Likes

I only now just had it work outside of Studio when in an actual server, don’t know why it’s like that and if there’s anything I can do about that. Thanks so much.

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