Switching to TextChatService: Easy Coding & Snippets to Get You Started!

Recently (18 days ago), Roblox locked all access to the previous chat version (LegacyChatService)

First off, I will say that I understand that adapting to this new change can be challenging, but the benefits of the TextChatService (TCS) far outweigh any difficulties you may be experiencing. TCS is a significant improvement over the LegacyChatService (LCS). To facilitate a smooth transition, I’m sharing some code snippets that you’ll recognise, now tailored for the new chat service. I’m confident these resources will make the process easier for everyone!

TextChatService enhances our chatting experience and helps keep younger players (who are often our troublemakers😂) safe on the platform, creating a more secure environment for everyone.

– TUTORIAL STARTS HERE –

Since Roblox restricted access to the old chat version, many functions have changed, including the function to send system messages.

It used to be done like this:

local StarterGui = game:GetService("StarterGui")
	StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "Welcome to my Christian Minecraft Server!",
		Color = Color3.new(1, 1, 1), -- white text
		Font = Enum.Font.SourceSansBold,
		FontSize = Enum.FontSize.Size24
	})

Which now translates to this:

local Message = "Welcome to my Christian Minecraft Server!"
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)

If I left anything out or made any mistakes, please let me know.

How to make Channels
local Players = game.Players
local TextChannelService = game:GetService("TextChatService")
local CTC = TextChannelService:WaitForChild("ChannelTabsConfiguration")
local textChannels = TextChannelService:WaitForChild("TextChannels")
CTC.Enabled = true


local newTextChannel = Instance.new("TextChannel")
newTextChannel.Name = "NewTextChannel"
newTextChannel.Parent = textChannels
How to add Players to channels

To add a certain player to a channel, you have to use this function:

 newTextChannel:AddUserAsync(player.UserId)

Or if you want to add any player who joins, you can use this function:

Players.PlayerAdded:Connect(function(player: Player)
	newTextChannel:AddUserAsync(player.UserId)
end)

To add someone to a channel if they have a certain rank in a group. You would use this function:

Players.PlayerAdded:Connect(function(player: Player)
	Players.PlayerAdded:Connect(function(player: Player)
	local lowestrank = 254
	local plrrank = player:GetRankInGroup(0)
	if plrrank >= lowestrank then
		newTextChannel:AddUserAsync(player.UserId)
	end
end)
end)

Or if you want people in a certain group to access the channel, you can use this function:

Players.PlayerAdded:Connect(function(player: Player)
	local GroupID = 0
	local plrIsInGroup = player:IsInGroup(GroupID)
	if plrIsInGroup then
		newTextChannel:AddUserAsync(player.UserId)
	end
end)
How to send messages to players

To send messages to players through the server, you would have to follow these instructions:

  1. Make a RemoteEvent and name it whatever you desire, “ServerToClient” in my example.
  2. Make a server script and paste the code below into the script.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SendChatMessage = ReplicatedStorage:FindFirstChild("ServerToClient")

function SendMessage(player, Message)
SendChatMessage:FireClient(player, Message)
end
  1. Now, make a Local Script in StarterGUI or StarterPlayer and paste the code below into that script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage:WaitForChild("ServerToClient").OnClientEvent:Connect(function(message)
	game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(message)
end)
  1. Now you can give your SendMessage function a reason to be there. Paste this under your SendMessage Function in your Server Script!
Players.PlayerAdded:Connect(function(player: Player)
	local message = "Welcome to " ..game.Name.. "!"
	SendMessage(player, message)
	end)
How to make Chat Tags

You can use this video by @Blufinityy to make a chat tag system:
How To Create CHAT TAGS With TextChatService (Roblox Studio)

I recommend using the full tutorial, but for lazy people like me, here is the full script:

local textChatService = game:GetService("TextChatService")

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	
	if message.TextSource then
		local player = game:GetService("Players"):GetPlayerByUserId(message.TextSource.UserId)
		if player.Name == "HashtagBlu_YT" then --EDIT NAME HERE
			properties.PrefixText = "<font color='#00ffee'>[Developer]</font> " .. "<font color='#ff8400'>[W Rizz]</font> " .. message.PrefixText -- EDIT HTML HERE
			
		end
		
	end
	
	return properties
	
end
How to make Commands
  1. Add a TextChatCommand in TextChatService and name it SizeCommand
  2. Change the PrimaryAlias value to /grow and the SecondaryAlias value to /shrink
  3. Insert a Server Script into ServerScriptService and name it “CommandHandler”
  4. Paste the script below into the CommandHandler Script:
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

local sizeCommand: TextChatCommand = TextChatService:WaitForChild("SizeCommand")

sizeCommand.Triggered:Connect(function(textSource, message)
	local scaleMult = 1
	local messageWords = string.split(message, " ")
	if messageWords[1] == "/grow" then
		scaleMult = 2
	elseif messageWords[1] == "/shrink" then
		scaleMult = 0.5
	end

	local player = Players:GetPlayerByUserId(textSource.UserId)
	if player then
		local character = player.Character
		if character then
			local humanoid = character:FindFirstChildWhichIsA("Humanoid")
			if humanoid then
				for _, child in humanoid:GetChildren() do
					if child:IsA("NumberValue") then
						child.Value *= scaleMult
					end
				end
			end
		end
	end
end)

Thank you so much for taking the time to read through my post! If you found it helpful, I’d love to hear your thoughts—feel free to like or reply to share your feedback, especially since this is my first big informative post. Your support means a lot!

I did put a lot of work into this, and it would be nice to see who I helped!

8 Likes

Nice tutorial, I’ve see a lot of people struggling with the new api on this forum. I’d suggest adding a section or stuff about some of the events and callbacks that are more feature specific (Like ShouldDeliverCallback, MessageReceived, and SendingMessage although this one is probably more specific to custom chats)

Moreover, the documentation about TextChatMessage is actually wrong here, which I think is important to point out
image
TextChatMessage.Text can actually be unfiltered in some cases, for example from the SendingMessage event (I’ve tested it). The event is fired before the message goes through the filter, which is why it is unfiltered

I’m also not fond of the ChatCommand script example you’ve used, and the one from the documentation (which is very similar), as merging two commands into a single TextChatCommand object is not ideal, considering there can only be 2 aliases, as so is only applicable in some specific cases. The alias system I believe is more meant to be for, well, an alias (ie /help and /?)


Very debatable. Very very debatable. But I don’t want to get into that… Well I’ll just say that to me, TextChatService is easier on the surface, but if you try to do something more complex, you have to break your skull against the wall. Oh why did I get into that…

Also, even though they said april 30th would be the last day for the LegacyChat, they have only begun migrating experiences recently, so the 18 days ago thing is not so accurate. Not very important details, but figured I’d let you know

Thank you for the feedback. I will try to update this post a bit later.

I did refer to the documentation, and I found it a bit strange because an alias is meant to be an alternative name. However, they might be simplifying things for beginners.

I completely agree with this, but I hope it will get easier as we progress.

That’s interesting; I didn’t actually know that because every game has updated beforehand due to the big scare.

Thank you so much for your feedback! I really appreciate you sharing this information with me—I wasn’t aware of it all before!

1 Like