Chat text system help

Hello I was trying to make a chat tag system with ai and it won’t work. I have done so many prototype and it won’t work. Can you please help me?

I Really would appreciate it!

TagModule

local ChatTag = {
	['Main'] = {
		['Groupid'] = 1234
	},

	['Tags'] = {
		['VipDog'] = {
			['Rank'] = 100,
			['TagText'] = "✨Vip Dog",
			['TagC'] = Color3.fromRGB(119, 237, 72), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(255, 255, 255),
			['priority'] = 1
		},

		['Supporter'] = {
			['Rank'] = 101,
			['TagText'] = "⭐️Supporter",
			['TagC'] = Color3.fromRGB(234, 231, 1), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(255, 255, 255),
			['priority'] = 2
		},

		['Partner'] = {
			['Rank'] = 110,
			['TagText'] = "🔥Partner",
			['TagC'] = Color3.fromRGB(255, 140, 7), 
			['NameC'] = Color3.fromRGB(255, 213, 7), 
			['ChatC'] = Color3.fromRGB(255, 255, 255),
			['priority'] = 3
		},

		['Affiliate'] = {
			['Rank'] = 111,
			['TagText'] = "🛠️Affiliate",
			['TagC'] = Color3.fromRGB(131, 254, 236), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(255, 255, 255),
			['priority'] = 4
		},

		['Moderator'] = {
			['Rank'] = 200,
			['TagText'] = "🔧Moderator",
			['TagC'] = Color3.fromRGB(225, 169, 245), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(216, 193, 229),
			['priority'] = 5
		},

		['Admin'] = {
			['Rank'] = 202,
			['TagText'] = "🛠️Admin",
			['TagC'] = Color3.fromRGB(155, 29, 240), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(216, 193, 229),
			['priority'] = 6
		},

		['CommunityManager'] = {
			['Rank'] = 203,
			['TagText'] = "🌴Community manager",
			['TagC'] = Color3.fromRGB(42, 240, 189), 
			['NameC'] = Color3.fromRGB(42, 240, 189), 
			['ChatC'] = Color3.fromRGB(204, 255, 231),
			['priority'] = 7
		},

		['HeadofStaff'] = {
			['Rank'] = 212,
			['TagText'] = "🛠️Head of Staff",
			['TagC'] = Color3.fromRGB(155, 29, 240), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(216, 193, 229),
			['priority'] = 8
		},

		['President'] = {
			['Rank'] = 214,
			['TagText'] = "🛠️President",
			['TagC'] = Color3.fromRGB(155, 29, 240), 
			['NameC'] = Color3.fromRGB(179, 182, 183), 
			['ChatC'] = Color3.fromRGB(216, 193, 229),
			['priority'] = 9
		},

		['Developer2'] = {
			['Rank'] = 253,
			['TagText'] = "🔨Developer",
			['TagC'] = Color3.fromRGB(255, 38, 0), 
			['NameC'] = Color3.fromRGB(43, 131, 255), 
			['ChatC'] = Color3.fromRGB(255, 81, 26),
			['priority'] = 10
		},

		['Developer'] = {
			['Rank'] = 254,
			['TagText'] = "🔨Developer",
			['TagC'] = Color3.fromRGB(255, 38, 0), 
			['NameC'] = Color3.fromRGB(43, 131, 255), 
			['ChatC'] = Color3.fromRGB(255, 81, 26),
			['priority'] = 11
		},

		['God'] = {
			['Rank'] = 255,
			['TagText'] = "⚡God",
			['TagC'] = Color3.fromRGB(255, 251, 0), 
			['NameC'] = Color3.fromRGB(255, 64, 255), 
			['ChatC'] = Color3.fromRGB(210, 203, 94),
			['priority'] = 12
		},
	}
}

return ChatTag

Script

local ChatService = game:GetService("Chat")
local ChatTag = require(script.Parent.TagModule)

-- Define default colors for when the rank doesn't have corresponding tag data
local defaultNameColor = Color3.fromRGB(179, 182, 183)
local defaultChatColor = Color3.fromRGB(255, 255, 255)

game.Players.PlayerAdded:Connect(function(player)
	if player:IsInGroup(ChatTag.Main.Groupid) then
		local playerRank = player:GetRankInGroup(ChatTag.Main.Groupid)
		print("Player Rank:", playerRank) -- Print the player's rank for debugging

		local tags = {}

		-- Iterate through the tags and check if the rank matches
		for _, tagData in pairs(ChatTag.Tags) do
			if tagData.Rank and tagData.Rank <= playerRank then
				local tag = {
					TagText = tagData.TagText,
					TagColor = tagData.TagC,
					Priority = tagData.priority
				}
				table.insert(tags, tag)
			end
		end

		-- Sort tags based on priority
		table.sort(tags, function(a, b)
			return a.Priority < b.Priority
		end)

		print("Tags:")
		for _, tag in ipairs(tags) do
			print("  ", tag.TagText) -- Print the tags for debugging
		end

		local speakerName = player.Name .. "_ChatSpeaker"
		local speaker = ChatService:GetSpeaker(speakerName)
		if not speaker then
			speaker = ChatService:AddSpeaker(speakerName)
		end

		coroutine.wrap(function()
			speaker:SetExtraData("Tags", tags)
			if tags[#tags] then
				speaker:SetExtraData("NameColor", tags[#tags].TagColor)
				speaker:SetExtraData("ChatColor", tags[#tags].TagColor)
			else
				-- Set default colors if no corresponding tag data is found
				speaker:SetExtraData("NameColor", defaultNameColor)
				speaker:SetExtraData("ChatColor", defaultChatColor)
			end
		end)()
	end
end)

Thank you

what exactly isn’t working

(character limit ignore this)

1 Like

The chat tag everything about it

does it have errors or warnings

I have the right rank

can you show me output or console?

1 Like

1 Like

are u using textchatservice or the legacy one

2 Likes

I am using legacy
(I’m sorry I’m not giving you enough information)

1 Like

no it’s okay

(character limit ahhh)

2 Likes

How is it going?

(Character limit)

1 Like

Not sure if you’ve figured it out yet, but have you tried using:
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
or
local s = game:GetService("Chat"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")
Instead? since requiring it by just chat will not work and will make any chatservice syntax invalid like in the output you showed above

1 Like

No I not
(Character limit ABC)