How would I make several chat tags for a player, with the method you would change DefaultChatMessage and add this to it;
if info and info.title then
formatUseName = string.format(info.title .. " | %s:", fromSpeaker)
useNameColor = info.color
else
formatUseName = string.format("%s:", fromSpeaker)
end
Then have a module named title module. What I am trying to do is make several chat tags for the same player, not sure how to do this without errors.
You should create a list of tags for the player and then form a new string based off of it. This can be done by iterating through a list and using concatenation to effectively append new tags.
local tagList = {"A", "B", "C"}
local tagString do
tagString = ""
for _, tag in pairs(tagList) do
tagString = tagString.." "..tag
end
end
You can then use the newly formed string to place in the tag area.
Why not use the Lua Chat System api? It let’s you easily add multiple tags to a specific person:
local DefaultTags = {
{TagText = "Player", TagColor = Color3.new(0,0,1)}, --1st tag
{TagText = "Rank 1", TagColor = Color3.new(1,0,0)}, --2nd tag
}
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local All = ChatService:GetChannel("All")
All.SpeakerJoined:Connect(function(name)
local speaker = ChatService:GetSpeaker(name)
if speaker and speaker:GetPlayer() then --make sure it isn't a chatbot or such
speaker:SetExtraData("Tags", DefaultTags)
end
end)
Better yet, on this same topic, you can do this without relying on a speaker joining a channel (that’s a fairly weird solution). Set tags right as a speaker gets registered with the ChatService. Another note that you don’t need to wait for the ChatService module; cloning is implicit and ChatService is available when the ChatServiceRunner is.
I posted this same code on another thread, I’ll repost it here due to its relevance.
local ServerScriptService = game:GetService("ServerScriptService")
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)
local SPECIAL_DATA = {
[6809102] = {
ChatColor = BrickColor.new("Persimmon").Color,
Tags = {
{
TagText = "Developer",
TagColor = BrickColor.new("Lime green").Color,
}
-- Other tags here
}
-- Other message formats here
},
-- Other user here
}
local function handleSpeaker(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
if player then
local extraData = SPECIAL_DATA[player.UserId]
if extraData then
for key, value in pairs(extraData) do
speaker:SetExtraData(key, value)
end
end
end
end
ChatService.SpeakerAdded:Connect(handleSpeaker)
for _, speakerName in pairs(ChatService:GetSpeakerList()) do
handleSpeaker(speakerName)
end
This is also how ExtraDataInitializer assigns chat colours for staff and interns.