What I am wanting to try and do is to set up proper chat tag messages for example
[Admin] User: hello!
The problem is that despite having somewhat thinking I have been ‘successful,’ which fortunately enough the client script seems to give the impression that it actually has sent, I did not realize that OnIncomingMessage actually will not work, and that it only shows up on the user’s screen, rather to everyone else in game, which is what I want.
I have looked around and looked at TextChatService posts relevant to chat tag, and that my case seems to be a bit different cause I do believe I was unable to fully resolve my issue and has left me perplexed and going in circles.
What I also wish to beg questioning is if I may need to somehow implement a server script? But that also begs the question cause I am unsure if my ‘module’ script under Adonis admin counts toward that, given though the command module is ‘Server-Chattag’
If anything needs clarified please do not hesitate to respond, I wish to keep this open to questions based on this post alone, and if there is any insight that can be given.
Scripts shared below:
Admin command script module plugin:
return function(Vargs)
local server, service = Vargs.Server, Vargs.Service
-- Session-based storage for toggles
local TagToggles = {}
server.Commands.HIAChatTag = {
Prefix = server.Settings.PlayerPrefix; -- Prefix to use for command
Commands = {"chattag"}; -- Commands
Args = {}; -- Command arguments
Description = "Toggles the HIA chat tag & chat color"; -- Command Description
Hidden = false; -- Is it hidden from the command list?
Fun = false; -- Is it fun?
RequiredGroupId = 2733801;
RequiredGroupRank = 1;
AdminLevel = "Moderators"; -- Admin level; If using settings.CustomRanks set this to the custom rank name (eg. "Baristas")
Function = function(plr, args)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChatTagEvent = ReplicatedStorage:FindFirstChild("ChatTagEvent")
if not ChatTagEvent then
warn("ChatTagEvent RemoteEvent not found in ReplicatedStorage")
return
end
local groupId = 2733801 -- Update to match RequiredGroupId
local ranks = {
["255"] = {TagText = "CEO", TagColor = Color3.fromRGB(255, 0, 0)},
["254"] = {TagText = "Vice CEO", TagColor = Color3.fromRGB(66, 134, 244)},
["2"] = {TagText = "Moderator", TagColor = Color3.fromRGB(31, 139, 76)},
["1"] = {TagText = "Intern", TagColor = Color3.fromRGB(44, 198, 108)},
}
local tagData = nil
-- Special override for a specific user
if plr.UserId == 79262008 then
tagData = {
TagText = "Vice CEO",
TagColor = Color3.fromRGB(66, 134, 244),
ChatColor = Color3.fromRGB(205, 244, 250)
}
else
local info = server.Admin.GetPlayerGroup(plr, groupId)
local rankData = ranks[tostring(info.Rank)]
if rankData then
tagData = {
TagText = rankData.TagText,
TagColor = rankData.TagColor,
ChatColor = Color3.fromRGB(205, 244, 250)
}
end
end
-- Toggle tag
local result
if TagToggles[plr.UserId] then
TagToggles[plr.UserId] = nil
-- Fire the event with nil to disable the tag for this player
ChatTagEvent:FireClient(plr, nil)
result = false
else
TagToggles[plr.UserId] = tagData
-- Fire the event to update the tag for this player
ChatTagEvent:FireClient(plr, tagData)
-- Broadcast to all players to update the tag on their screen
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if player ~= plr then
ChatTagEvent:FireClient(player, tagData)
end
end
result = true
end
-- Feedback to the admin
server.Functions.Hint("You have " .. (result and "enabled" or "disabled") .. " your chat tag/color", {plr})
end
}
end
Client script plugin
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local ChatTagEvent = ReplicatedStorage:WaitForChild("ChatTagEvent")
local localPlayer = Players.LocalPlayer
-- State cache
local isEnabled = false
local currentTagData = nil
ChatTagEvent.OnClientEvent:Connect(function(tagData)
isEnabled = tagData ~= nil
currentTagData = tagData
end)
-- Override the default chat input (before sending to server)
TextChatService.OnIncomingMessage = function(message)
-- Process only TextChatMessages from the local player with an active tag
if message:IsA("TextChatMessage") and message.TextSource and message.TextSource.UserId == localPlayer.UserId and isEnabled and currentTagData then
-- Send the message and tag data to the server for processing
local props = Instance.new("TextChatMessageProperties")
local tag = currentTagData
-- Calculate RGB values (0-255)
local tagR, tagG, tagB = math.floor(tag.TagColor.R * 255), math.floor(tag.TagColor.G * 255), math.floor(tag.TagColor.B * 255)
local chatR, chatG, chatB = math.floor(tag.ChatColor.R * 255), math.floor(tag.ChatColor.G * 255), math.floor(tag.ChatColor.B * 255)
-- Format colors for rich text
local tagColor = `rgb({tagR}, {tagG}, {tagB})`
local chatColor = `rgb({chatR}, {chatG}, {chatB})`
-- Format the tag part with its color
local tagText = `<font color="{tagColor}">[{tag.TagText}]</font>`
-- Format the name part using DisplayName, brackets, and a colon (no specific color tag here, uses default name color)
local nameText = `{localPlayer.DisplayName}:`
-- Combine tag and name for the final display name in chat
props.PrefixText = tagText .. " " .. nameText
-- Format the message text with its color
props.Text = `<font color="{chatColor}">` .. message.Text .. "</font>"
return props
end
return nil
end
Also to provide, I have shared screenshots below that show how it appears in the current case I have.