I can’t seem to make a custom chat tags for different teams. I have look and can’t fine anything
Tags before name in chat.
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
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)
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
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.
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
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"]
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