I’m trying to figure out a way to say “/tog” in chat and then it’ll toggle the chat tags. Also maybe allow only the people with chat tags to use the command. I don’t know how to do it… I’ve been searching on youtube and on the developer hub for a while, haven’t seen anything that can help…
Heres the script:
local ServerScriptService = game:GetService("ServerScriptService")
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)
local SPECIAL_DATA = {
[890996562] = {--WxlfEclxpse
ChatColor = BrickColor.new("White").Color,
Tags = {
{
TagText = "Co-Founder",
TagColor = Color3.new(0.991318, 0.573877, 0.249638),
},
{
TagText = "Developer",
TagColor = Color3.new(0.946151, 0.822858, 0.487465),
}
-- Other tags here
}
-- Other message formats here
},
-- Other user here
[3634738499] = { --Rat
ChatColor = BrickColor.new("White").Color,
Tags = {
{
TagText = "Concept Artist",
TagColor = Color3.new(0.233143, 0.878538, 0.692668),
},
{
TagText = "Content Creator",
TagColor = Color3.new(0.309743, 1, 0.622644),
}
-- Other tags here
}
-- Other message formats here
},
--Other user here
[1143428772] = {--Dragon826K
ChatColor = BrickColor.new("White").Color,
Tags = {
{
TagText = "Head Concept Artist",
TagColor = Color3.new(0.190127, 0.687053, 0.549599),
},
{
TagText = "Mod",
TagColor = Color3.new(0.712535, 0.372519, 0.949508),
}
-- Other tags here
}
-- Other message formats here
},
}
local function handleSpeaker(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
if player then
local extraData = SPECIAL_DATA[player.UserId]
if extraData then
for key, value in pairs(extraData) do
speaker:SetExtraData(key, value)
end
end
end
end
ChatService.SpeakerAdded:Connect(handleSpeaker)
for _, speakerName in pairs(ChatService:GetSpeakerList()) do
handleSpeaker(speakerName)
end
local function toggleoff(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
if player then
if SPECIAL_DATA[player.UserId] then
speaker:SetExtraData('Tags', {})
end
end
end
setting the data to {} returns it to default. Also, it seems white is the ChatColor for every special tag, so you don’t need to change it back, but you can if you want.
I put this script after the script i pasted above. Do i have to say a certain word for it to toggle? Cause when i speak in chat, it doesn’t do anything.
local function toggleoff(speakerName)
print(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
if player then
if SPECIAL_DATA[player.UserId] then
print("Resetting tags")
speaker:SetExtraData('Tags', {})
else
print("Doesn't have special tags")
end
else
print("No player?")
end
end
local toggles = {}
local function toggle(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
if player then
if SPECIAL_DATA[player.UserId] then
if not toggles[player.UserId] then
toggles[player.UserId] = true
speaker:SetExtraData('Tags', {})
else
toggles[player.UserId] = false
speaker:SetExtraData('Tags', SPECIAL_DATA[player.UserId].Tags)
end
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg:lower() == "/tog" then
toggle(plr.Name)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
if toggles[plr.UserId] then
toggles[plr.UserId] = nil
end
end)
for i, plr in pairs(game.Players:GetPlayers()) do
plr.Chatted:Connect(function(msg)
if msg:lower() == "/tog" then
toggle(plr.Name)
end
end)
end
This combined all of the stuff I provided, so replace everything I had provided.
You can set up a .Chatted event for the /tog command; and a for loop to check if the player is whitelisted to use it, if so, use a bool variable to check if it’s toggled or not, then, just readd the tags back.