Hi! I am trying to make a /tog system so admins can toggle their chattag on and off.
but I got that error everytime I try to chat after I use /tog.

I am using attributes to set the rank.
Attribute Script
local Players = game:GetService("Players")
local groupId = 10618939
Players.PlayerAdded:Connect(function(player)
local success, isInGroup = pcall(function()
return player:IsInGroup(groupId)
end)
if success and isInGroup then
local rank = player:GetRankInGroup(groupId)
player:SetAttribute("GroupRank", rank)
else
player:SetAttribute("GroupRank", 0)
end
end)
Chat Tag Script
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local rankTags = {
[255] = {TagText = "⭐ | [Owner]", TagColor = Color3.fromRGB(255, 255, 0)},
[254] = {TagText = "🔥 | [Co-Owner]", TagColor = Color3.fromRGB(255, 165, 0)},
[253] = {TagText = "🛠️ | [Developer]", TagColor = Color3.fromRGB(0, 255, 0)},
[100] = {TagText = "⚡ | [Admin]", TagColor = Color3.fromRGB(255, 0, 0)},
}
local toggledPlayers = {}
TextChatService.OnIncomingMessage = function(message)
local properties = Instance.new("TextChatMessageProperties")
local textSource = message.TextSource
local player = Players:GetPlayerByUserId(textSource.UserId)
if player then
if message.Text:lower() == "/tog" then
if toggledPlayers[player.UserId] == true then
toggledPlayers[player.UserId] = false
else
toggledPlayers[player.UserId] = true
end
end
if toggledPlayers[player.UserId] == false then
properties.PrefixText = nil
else
local rank = player:GetAttribute("GroupRank")
local tagInfo = rankTags[rank]
if tagInfo then
local tagText = string.format('<font color="#%02X%02X%02X">%s</font> ',
tagInfo.TagColor.R * 255, tagInfo.TagColor.G * 255, tagInfo.TagColor.B * 255,
tagInfo.TagText
)
properties.PrefixText = tagText .. (message.PrefixText or "")
end
end
end
return properties
end