Dynamic Tags in the Chat

I’m trying to add the players rank before their name in the chat. The level is stored in server storage.

I’ve got it to work so far with this method (highlighted my added code which is in the default chat):

Picture (ExtraDataInitializer)

But, as this function is only called when a new speaker is added, the rank value stays static even when it updates in-game.

I’ve considered adding a SentMessage function and adding the rank each time a message is sent but this seems unnecessary. I’ve also tried adding a simple .Changed() function into the NewSpeaker function, but then the whole chat breaks. (lol)

Does anyone have any experience adding dynamic tags to the chat who could solve this problem? Thanks in advance!

You don’t need to edit that module. You can use the ChatService api’s function SetExtraData to dynamically assign tags to players.

Example:

local ChatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Admins = {
    mario118118 = true
}
game.Players.PlayerAdded:Connect(function(plr)
    if Admins[plr.Name] then
        ChatService:GetSpeaker(plr.Name):SetExtraData("Tags", {{TagText = "Admin", TagColor = Color3.new(1,0,0)}})
    end
end
7 Likes

NewSpeaker is responsible for creating a Speaker object within the ChatService. A Speaker represents a player or an added speaker to send messages in the chat. Therefore, you would also need to fetch the Speaker to act upon it. NewSpeaker creates a Speaker and returns the Speaker, so conversely to edit the Speaker again you’d need to fetch it.

You’re probably looking to use the ChatService module to get speakers. It supports a GetSpeaker method. Once you have the Speaker (ChatSpeaker), see the ChatSpeaker module. Supports the methods you’re looking for. Ideally when a player’s rank updates, I’d assume all you need to do is set the extra data for the Speaker.

2 Likes

SetExtraData is not a valid method of ChatService. See my response above. ChatService can be used to fetch speakers and the methods of ChatSpeaker are used to set the extra data of a Speaker.

I said it’s a function of the ChatService api, not the ChatService object directly. I edited my answer.

It’s not. That’s a misleading answer to provide. Extra data functions are not associated with the ChatService, depending on your context - whether you’re referring to the raw Chat service or the ChatService module intended to assist in facilitating functions for the Lua Chat System to external code.

The code sample you provided is a perfectly viable answer but I’d caution you against doing that in the instance that a nil Speaker is returned, which would consequently throw an error for attempting to operate on a nil value and terminate the thread. You should always verify that the return value from a callback is valid before operating on it.

1 Like

The purpose of my example code is to show the OP how he can dynamically change a speaker’s tags. The rest such as preventing errors is up to them.

And sorry, I should’ve probably said Lua Chat System api rather than ChatService api, but let’s not nitpick on naming the chat api.

This is a response I had to an older thread from a few months ago, and OP seemed to find it useful. You’ll find the ability to add Chat titles for users that hold a certain rank in the group on Line 197 of ExtraDataInitializer, which is inside the open sourced model I linked on this response:

1 Like

You provided that code so the least you could do is not make such code present a potential edge case. Furthermore, I’m not “nitpicking” naming. There are times when distinction is important to know because it can cause confusion or misconception in the future. The locations of methods is not the same as nitpicking naming. Please DM me if you have issues with my posts.

Guys, it’s okay! I understand what he meant.

Thanks for the responses!

2 Likes

If your issue has been solved you should mark the post which answered your question as the solution.

1 Like

Already did! Thank you for the link you sent as well, useful thread.