Hello, I am relatively new to TextChatService. By following some tutorials I have made this function in my local module.
function client.ApplyChatTag(name, color, plr)
local TextChatService = game:GetService("TextChatService")
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
if message.TextSource then
local playerChatting = message.TextSource
if playerChatting.Name == plr.Name then
properties.PrefixText = "<font color='"..color.."'>"..name.."</font> " .. message.PrefixText
end
end
return properties
end
end
I call this function from a local script whenever a player joins.
if table.find(variables.Developers, player.Name) then
client.ApplyChatTag("[🛠️ DEVELOPER]", "#fbff00", player)
end
This is an example of the Developer chat tag.
Now, it works fine on the player with the chat tag’s end. Although the chat tag does not apply for other clients. I’ve tried other solutions such as firing a ton of remote events through the player’s client to the server and to everyone’s client to update their chat tag, but this only works for the most recent player to join.
So my main issue is just getting the chat tags to appear for everyone. Thanks!
Just wondering, when you do the chat tag thing, is it visible to everyone or just the client itself? It seems that since you’re doing all of this through local scripts, others wouldn’t be able to see the chat tag. Correct me if I’m wrong though, I’m not specialized in the TextChatService myself tbh
You probably wouldn’t wanna use TextChatService for this, instead use the ChatService module script
Also make sure you add the following code in a script in ServerScriptService
local tagName = "dev 💀💀" --change this to what you want the chat tag to be
local ServerScriptService = game:GetService("ServerScriptService") --define the service
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")) --define the chatservice
local Players = game:GetService("Players") --define players
ChatService.SpeakerAdded:Connect(function(plr) --check when a player is added and able to use chat
if table.find(variables.Developers, plr) then --check if the player is a developer
local Speaker = ChatService:GetSpeaker(plr) --define the speaker (player)
Speaker:SetExtraData('Tags', {{TagText = tagName, TagColor = Color3.fromRGB(4, 175, 236)}}) -- change the color if you want to
end
end)
The reason you’d wanna do this is because you want to get the chat tags to be serversided, therefore use ServerScriptService as well as the ChatService module instead of TextChatService. Kind of hard to explain, I recommend watching a tutorial on this if you want to learn more about this.
Does this work with the new ChatService instead of LeagcyChatService, if so can you send a tutorial using your method so I could go in more depth with this?
Yeah, I am quite confused on how this is meant to work, I don’t really want to use the LegacyChatService but I might have to considering the fact that chat tags using TextChatService only appear on the clients end and you can’t use TextChatService from a script.
local textChatService = game:GetService("TextChatService")
local developers = {
-- DEVELOPER IDS HERE
}
local function onIncomingMessage(message)
local properties = Instance.new("TextChatMessageProperties")
local playerChatting = message.TextSource
if playerChatting then
if table.find(developers, playerChatting.UserId) then
properties.PrefixText = "<font color='#fbff00'>[🛠️ DEVELOPER]</font> " .. message.PrefixText
end
end
return properties
end
textChatService.OnIncomingMessage = onIncomingMessage
This basically receives every single message that is sent to the client and checks if the player who sent it is a developer, and applies the chat tag if they are.
Edit: I have tested ingame and it works. @ZElectricitE if this works for you could you mark it as a solution for future readers?
What I realized is that on the first client, it shows the first client’s tag which is CO-OWNER and PRIME (which are the tags for the first client) then for the second client is only PRIME, I don’t know what’s causing this though. Can someone help?
tcs.OnIncomingMessage = function(msg)
local property = Instance.new("TextChatMessageProperties")
if msg.TextSource then
local player = players:GetPlayerByUserId(msg.TextSource.UserId)
local data = chatService:GetTag(player, player:GetRoleInGroup(game.CreatorId))
if player and not tableUtil.IsEmpty(data) then
local text = ""
for i,current in ipairs(data) do
text = text .. string.format("<font color='#%s'>[%s]</font>", current["Color"]:ToHex(), current["Name"])
if i == #data then
text = text .. " " .. msg.PrefixText
end
end
property.PrefixText = text
end
end
return property
end