Help with new textchatservice

I’m trying to migrate to the new TextChatService but have come across issues and need help.

I have two scripts, one is for prefixes and roles, the other is to make system messages.

– LocalScript ChatTags

repeat wait() until game:IsLoaded()
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

-- Function to determine the tag for a player based on rank
local function GetTagForPlayer(player)
	local highestPriorityTag = nil
	local highestPriority = -1

	-- Iterate through ranks to determine the highest priority tag
	for role, data in pairs(ranks) do
		if data.Rank and player:GetRankInGroup(GroupID) == data.Rank then
			if data.Priority > highestPriority then
				highestPriority = data.Priority
				highestPriorityTag = data.Prefix
			end
		elseif data.Ranks and table.find(data.Ranks, player:GetRankInGroup(GroupID)) then
			if data.Priority > highestPriority then
				highestPriority = data.Priority
				highestPriorityTag = data.Prefix
			end
		elseif role == "GroupMember" and player:IsInGroup(GroupID) then
			if data.Priority > highestPriority then
				highestPriority = data.Priority
				highestPriorityTag = data.Prefix
			end
		end
	end

	return highestPriorityTag
end

-- Function to handle incoming chat messages
local function OnIncomingMessage(message)
	-- Wait for UserId to be available
	repeat wait() until message.TextSource and message.TextSource.UserId

	local player = Players:GetPlayerByUserId(message.TextSource.UserId)
	if player then
		local tagPrefix = GetTagForPlayer(player)
		if tagPrefix then
			local properties = Instance.new("TextChatMessageProperties")
			properties.PrefixText = tagPrefix .. message.PrefixText
			return properties
		end
	end
end

-- Connect the chat message handler
TextChatService.OnIncomingMessage = OnIncomingMessage

-- Function to initialize player tags on join
local function SetupTagsForPlayer(player)
	-- Assign tag based on rank when the player joins
	player.CharacterAdded:Connect(function()
		local tagPrefix = GetTagForPlayer(player)
		if tagPrefix then
			print(player.Name .. " has been assigned tag: " .. tagPrefix)
		end
	end)
end

-- Apply to new players
Players.PlayerAdded:Connect(SetupTagsForPlayer)

-- Apply to players already in the game
for _, player in ipairs(Players:GetPlayers()) do
	SetupTagsForPlayer(player)
end

– LocalScript Welcomer

local function generateSystemMessage(MessageDictionary: array)
	return '<font color="#'..MessageDictionary["Color"]..'"><font size="'..MessageDictionary["FontSize"]..'"><font face="'..MessageDictionary["Font"]..'">'..MessageDictionary["Text"]..'</font></font></font>'
end

local Choices = {
	"Test"
}

while true do
	local randomTip = math.random(1, #Choices)
	local pickedTip = Choices[randomTip]

	local chat = game:GetService("TextChatService")
	local channel = chat:WaitForChild("TextChannels"):WaitForChild("RBXSystem")

	channel:DisplaySystemMessage(
		generateSystemMessage({
			Text = "[SYSTEM] "..tostring(pickedTip);
			Font = "Gotham";
			Color = Color3.fromRGB(255,0,0):ToHex();
			FontSize = "17";
		})
	)
	task.wait(1)
end

The system messages work fine if I disable my ChatTags script, but if I don’t then the system messages will not show up in chat - however if I debug them it will display that they were sent successfully.