I am trying to give players chat tags to show their rank. Their rank changes as they play the game.
I've found that the easiest way to give a player a chat tag is to use "speaker:SetExtraData". However, when the player gains a new rank and I use "speaker:SetExtraData" to assign them their new rank, then both ranks will show up before their name in the chat.
For example: A player has the rank "Peasant" and types "hi" in the chat. It will look like this: Then the player gains the "Cultist" rank, now they type hi again. It will look like this: That makes the question: Is it possible to clean the speaker's "ExtraData", so when I add more ExtraData then the old ExtraData will not persist and stack up several chat tags at once?
Any help or just a point in the right direction would be greatly appreciated.
Ok, lets try it!
First Step : We need to know what is the "SetExtraData" function is. But we can read a article of this on the DevForum. So let's skip this.
Second Step : Second, we need to know how we can insert "Tags" so lets see how...
local player = game:GetService("Players") local SSS = game:GetService("ServerScriptService") local chatService = require(SSS:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService)) chatService.SpeakerAdded:Connect(function(playername) local speaker = chatService:GetSpeaker(playername) if (player[playername].Stats.IsMod.Value == true and (players[playername].TempsStats.ShowTag.Value == true then speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52)) speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130)) speaker:SetExtraData('Tags', {{TagText = "Moderator", TagColor = Color3.fromRGB(255, 52, 52)}}) end end)
So, that's the way we can add chatTags to our game... But... How we can desactivate it? Well. is easy!
Only we need to change something...
Third Step : Enjoy coding! You always have to enjoy what are you doing!
Lets get into code!
speaker:SetExtraData('Tags', nil)
And that's all!
I hope my answer already solve your question.
Keep scripting