How can I make a team chat tags?

I can’t seem to make a custom chat tags for different teams. I have look and can’t fine anything

  1. Tags before name in chat.
  2. Be able to customize what those tags say.

How do I do this

This script is in StarterPlayerScripts as a local script

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

local TeamAN = "Animator"

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		if player.Team == TeamAN then
			properties.PrefixText = "<font color='#F5CD30'>[Animator]</font> " .. message.PrefixText
		end
	end

	return properties
end
10 Likes

To make chat tags it first of all has to be inside a Server Script, if possible inside of ServerScriptService.
There is multiple methods on how to do it: Either trough TextChatService or the deprecated ChatServiceRunner.

I personally do not know on how to do it inside of the TextChatService, but the following is the ChatServiceRunner method I use inside of my games:

local function SetTag(Speaker, Player, Tag, Color)
	if Speaker then
		Speaker:SetExtraData("Tags", {{TagText = Tag, TagColor = Color}})
	end
end
task.spawn(function()
	local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
	ChatService.SpeakerAdded:Connect(function(PlayerName)
		local Player = game:GetService("Players")[PlayerName]
		local Speaker = ChatService:GetSpeaker(PlayerName)
		if Player and Speaker then
			SetTag(Speaker, Player, "Chat Tag", Color3.new(0.470588, 0.470588, 0.470588))
		end
	end)
end)
3 Likes

That makes a tag but not a team tag and also that did not work

1 Like

local script in starterplayerscripts:

local tcs = game:GetService("TextChatService")
local teamInfo = {
  Animator = {
     Color = Color3.fromRGB(animatorcolor)
   };
   --fill in the rest
}

tcs.OnIncomingMessage = function(msg)
   local properties = Instance.new("TextChatMessageProperties")
   if msg.TextSource then
	   properties.PrefixText = "<font color='#'"..Color3:ToHex(teamInfo[msg.TextSource.Team.Name].Color)..">["..msg.TextSource.Team.Name.."]</font> "..msg.PrefixText
   end
   return properties
end
1 Like

you are comparing a team to a string.
it should be player.Team.Name == TeamAN

i don’t need to explain why this is dumb

1 Like

Do I remove that line for code

just replace the script with my new one

and add necessary modifications

That did not work--------------

What do you mean by this? Could you explain further?

I changed it I don’t need that

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

local chatTagData = {
	Animator = {
		Color = "#F5CD30",
		-- Text = "Awesome Animator",
	},
	--Programmer = {
	--	Color = "#A7C7E7",
	--	Text = "👨‍💻 Coder",
	--},
}

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		local data = chatTagData[player.Team.Name]
		if data then
			properties.PrefixText = `<font color='{data.Color}'>[{if data.Text then data.Text else player.Team.Name}]</font> ` .. message.PrefixText
		end
	end

	return properties
end

By default, team dictionaries that have an empty Text property have their tag text set to the team name, you can override this by adding a Text property.

You can add more teams by adding more team dictionaries to chatTagData. Note, to do this, a team with that name must exist.

2 Likes

That still did not work and there are not errors :frowning:

local tcs = game:GetService("TextChatService")
local teamInfo = {
  Animator = {
     Color = Color3.fromRGB(animatorcolor);
     Text = "Animator";
   };
   --fill in the rest
}

tcs.OnIncomingMessage = function(msg)
   local properties = Instance.new("TextChatMessageProperties")
   if msg.TextSource then
      local info = teamInfo[msg.TextSource.Team.Name]
      local color = "#"..Color3:ToHex(info["Color"])
      local team = info["Text"]
	  properties.PrefixText = string.format("<font color =%q>[%s]</font> %s", color, team, msg.PrefixText)
   end
   return properties
end

That still did not work. The script should be a local script in StarterPlayerScripts right?

are you using hexes in the ‘Color’ section?
if so, you could either convert it to Color3.fromRGB or change "#"..Color3:ToHex(info["Color"]) to info["Color"]

it hurts saying color as a british person

also yes, local script in starterplayerscripts

Sill did not work--------------

show me the current script you have

local tcs = game:GetService("TextChatService")
local teamInfo = {
	Animator = {
		Color = Color3.fromRGB(0,255,0);
		Text = "Animator";
	};
}

tcs.OnIncomingMessage = function(msg)
	local properties = Instance.new("TextChatMessageProperties")
	if msg.TextSource then
		local info = teamInfo[msg.TextSource.Team.Name]
		local color = info["Color"]
		local team = info["Text"]
		properties.PrefixText = string.format("<font color =%q>[%s]</font> %s", color, team, msg.PrefixText)
	end
	return properties
end

in teamInfo, you haven’t filled in the other teams. so if you’re not an animator, that’s why it doesnt work

At the stat of the game you have not team but I have a part the make you change team. So I hit the part and switch teams but I still don’t have a tag