I have this script which manages chat tags, which specifies a chat tag for staff members and one for vip gamepass owners. I am specified here and own vip, and my owner one overrides the vip. However, some mods can’t see their tags. Why is this? The entries are the same.
local MarketplaceService = game:GetService("MarketplaceService")
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)
-- Create a dictionary of special chat data (e.g. mods).
local SPECIAL_CHAT_DATA = {
-- I will only fill out one dictionary key for you as an example, do
-- the rest on your own time.
[776294655] = {
ChatColor = Color3.new(14, 76, 98),
Tags = {
{TagText = "Creator", TagColor = Color3.fromRGB(14, 76, 98)},
}
},
[387060256] = {
ChatColor = Color3.new(85, 170, 255),
Tags = {
{TagText = "Melon Shark", TagColor = Color3.fromRGB(85, 170, 255)},
}
},
[157066100] = {
ChatColor = Color3.new(255,255,0),
Tags = {
{TagText = "Moderator", TagColor = Color3.fromRGB(255,255,0)},
}
},
[278133397] = {
ChatColor = Color3.new(34,139,34),
Tags = {
{TagText = "Moderator", TagColor = Color3.fromRGB(34,139,34)},
}
},
[246403810] = {
ChatColor = Color3.new(221,214,225),
Tags = {
{TagText = "Moderator", TagColor = Color3.fromRGB(221,214,225)},
}
},
[144157339] = {
ChatColor = Color3.new(0,255,0),
Tags = {
{TagText = "Developer", TagColor = Color3.fromRGB(0,255,0)},
}
},
[125293735] = {
ChatColor = Color3.new(255,0,0),
Tags = {
{TagText = "Creator", TagColor = Color3.fromRGB(255,0,0)},
}
},
[1498144377] = {
ChatColor = Color3.new(0,35,102),
Tags = {
{TagText = "Developer", TagColor = Color3.fromRGB(0,35,102)},
}
},
[413969295] = {
ChatColor = Color3.new(0, 0, 255),
Tags = {
{TagText = "Moderator", TagColor = Color3.fromRGB(85, 170, 255)},
}
},
[413969295] = {
ChatColor = Color3.new(128,0,0),
Tags = {
{TagText = "Moderator", TagColor = Color3.fromRGB(128,0,0)},
}
},
[1037666502] = {
ChatColor = Color3.new(0, 0, 255),
Tags = {
{TagText = "Creator", TagColor = Color3.fromRGB(85, 170, 255)},
}
},
[157066100] = {
ChatColor = Color3.new(255,255,0),
Tags = {
{TagText = "Moderator", TagColor = Color3.fromRGB(255,255,0)},
}
},
-- etc
}
-- Again, make a table as a constant so you can edit here instead of
-- in a function. Your original code was creating tables every time
-- the function was called, which isn't good anyhow.
local VIP_CHAT_DATA = {
ChatColor = Color3.fromRGB(239, 184, 56),
Tags = {
{TagText = "VIP", TagColor = Color3.fromRGB(239, 184, 56)},
},
}
-- So if we need to change the pass, we can do it from here instead of
-- further into the code where it's less visible.
local GAME_PASS_ID = 9326348
-- Small tip: for the above tables, you can make submodules that return tables
-- on require. Would keep giant tables from being in the tags script.
-- To make things cleaner for us, to isolate this assignment bit and
-- to clearly show for example's sake, created this function.
local function applyExtraDataForSpeaker(speaker, dataTable)
for key, value in pairs(dataTable) do
speaker:SetExtraData(key, value)
end
end
-- Make sure to create a function like this. To catch speakers who may be added
-- ahead of SpeakerAdded being registered, some may not get tags.
local function speakerAdded(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
-- Player is available here! Do not use Players service!
local player = speaker:GetPlayer()
-- If this is a player speaker, proceed
if player then
-- Keep this flag handy for later.
local dataAddressed = false
-- Look for special data first: if they have it, apply it
local specialData = SPECIAL_CHAT_DATA[player.UserId]
if specialData then
applyExtraDataForSpeaker(speaker, specialData)
-- Flip our earlier flag dataAddressed for the if statement below
dataAddressed = true
end
-- Use the flag to determine if we should evaluate VIP next
if not dataAddressed then
local isVIP = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID)
-- If the player owns the VIP pass, give them VIP chat data. Our
-- earlier flag isn't needed anymore, so don't set it here.
if isVIP then
applyExtraDataForSpeaker(speaker, VIP_CHAT_DATA)
end
end
end
end
-- Hook the speakerAdded function to the SpeakerAdded event
-- and make sure all added speakers who didn't have
-- SpeakerAdded fired for them, gets the function called on them.
ChatService.SpeakerAdded:Connect(speakerAdded)
for _, speakerName in ipairs(ChatService:GetSpeakerList()) do
speakerAdded(speakerName)
end```