Changing chat type and other chat settings without forking

I honestly never knew that the Chat service had any events or function, nor did I expect that you could do this all the time. Now I only have to fork the chat when I want to give players a tag or a custom chat color, unless you have also something for that in your bag. But short question, does RegisterChatCallback need to be called before the window got created, or can I do it anytime? (Can’t test it out right now, Studio completely :b:roke)

5 Likes

RegisterChatCallback itself is used, as its name states, to register callbacks to the chat. The first argument of RegisterChatCallback accepts a ChatCallbackType Enum, so depending on which one you decide to use, that changes the necessities for your code. Specifically for OnCreatingChatWindow, the chat service calls InvokeChatCallback and fires off any functions registered to OnCreatingChatWindow before the chat window is created.

We keep our script in ReplicatedFirst so that the function is registered before the window is created. The same window of opportunity may not exist when placed elsewhere due to potential race conditions. Remember, the Lua Chat System and the LocalScript would be two entry points of code. There’s no guarantee your script will run before the setting of the chat window does. Placing it elsewhere though is worth a test.

As far as giving players tags and custom chat colours, that’s worth a quick tutorial on its own, but it is possible to give these items without forking the chat system as well. In fact, I currently do that right now for a group that I currently develop for. You are able to change these kinds of message appearances with another ChatCallbackType, OnClientFormattingMessage. I don’t typically have a use for it.

I’ll consider using my GitHub more actively seeing that I’ve been posting a lot of tutorial content recently, maybe I post the code there too. For now though, it may be slightly off topic, but I can show you how I currently assign tags.

The code is under this tab. Kept here so as not to disturb thread.
local ServerScriptService = game:GetService("ServerScriptService")

local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)

local SPECIAL_DATA = {
    [6809102] = {
        ChatColor = BrickColor.new("Persimmon").Color,
        Tags = {
            {
                TagText = "Developer",
                TagColor = BrickColor.new("Lime green").Color,
            }
        -- Other tags here
        }
        -- Other message formats here
    },
    -- Other user 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

Will consider removing the above code and moving this to a separate tutorial another day.

15 Likes

Is there anyway to set it to work for players with a set gamepass?

The chat tag code? Yes. The whole condition under if player then is subject to whatever checks and sets you want to apply to speakers. It’d be appreciated if you started a new thread if you were curious on how to do that though. The main point of this tutorial is chat settings, not message formatting. I just took a bit of time to answer that question quickly.

1 Like

I have found the answer to this API: Its the framerate of fading animations in the chat UI.

Do you know how specifically it works? I figure it’s related to some kind of animation FPS as per the name but I haven’t been able to crack the code on what values this contributes to, what changing it does and why the API is this way instead of just a value to determine over how long an animation should take to finish.

1 Like

So when you stop hovering over the chat long enough, it starts to fade, then when you hover over it again it pops right up. If you change the value of the API to say like 1 FPS. The chat fading animation will be super slow and it will be sorta lagging.

1 Like

I see, thanks for the information! I’ll try experimenting around with the values and checking the source, then make an update on the post clarifying what the setting is for.

1 Like

If you want the source its here: Customizing In-Experience Text Chat | Documentation - Roblox Creator Hub. Scroll down to the api reference: ChatFadingFPS.

I looked at that page already. The goal of listing all the settings via this tutorial is to reiterate the purpose of each setting in a quick, concise, accessible and easily understandable manner. :slight_smile:

1 Like

Hey developers! I just got a question about using this tutorial to make some edits to the ChatService and I made a new discovery while helping them that’s relevant to the thread. I will be updating it accordingly!

For the GeneralChannelName field, setting this to nil will remove the general channel. It will leave only the system channel then. Without the general channel, you can do your own management of chat channels, such as creating channels for alive and dead players in a round-based game where dead players not communicating with alive players is critical.

The purpose of the general channel is to echo messages from other channels, as well as to allow a hub for sending all messages. When you see the braces wrapping text before chat, that’s the echo effect. For example: when you see {Team} [colbert2677]: Hello!, this is the general channel catching a message from the Team channel. You can disable this behaviour with EchoMessagesInGeneralChannel, by the way.

The system channel’s use is self explanatory: sending system messages. For example, the message that a friend joined your server is a message in the system channel. You can simply call ChatService:RemoveChannel("System") to get rid of it, though any method trying to send a system message will throw a warning in the server console. You’ll have to fork to fully remove any uses of the system channel.

I originally did make note of what setting GeneralChannelName to nil does, but it was incorrect: it doesn’t prevent chats from other channels showing up, it completely disables the channel. So, with this new information in mind, I will be updating that table.

8 Likes

Post is outdated:

PlayerDisplayNamesEnabled and WhisperByDisplayName are now available to edit, false is the default for both of these (as of May 2021, I believe this is true). Doesn’t look to be documented on Lua Chat System — Client API — ChatSettings yet. (still not documented in June 2021 despite being out to most users)

2 Likes

Thank you for your post. I’ve noticed these settings a bit back but forgot to include them in the post since I don’t typically maintain old tutorials unless there’s a major point to be made. I’ll find some time soon to incorporate these two items into the post, along with any other potential settings changes.

The ChatSettings article itself pretty much makes this tutorial obsolete (and I didn’t even recognise the page existed at the time of writing, or maybe it didn’t, not sure). If you’d like, you can file a Developer Hub thread to request for an update to the ChatSettings article with the new settings.

3 Likes

I noticed those around October but I didn’t sadly see this article before. I’ve personally never seen the ChatSettings article before, until I saw it referenced in post #9 I think. I highly doubt Roblox will accept a request to update the DevHub page with the display name stuff as it is technically an unannounced feature despite people leaking it for a few months.

Hey! I have a question. So I have created a party System similar to the one on Minecraft Hypixel and I created a system to make channels so that players can chat separately in tabs in their respective parties. Everything is working except for one issue. When a party is disbanded and I delete the party channel each member is in, if a player still has the channel tab open, it remains there. They can type messages but they can’t send messages. I want to be able to find a way to delete the tab even if they are viewing/typing in it.

I think you have to remove the player from the channel, checking if the speaker is in the channel using IsInChannel and LeaveChannel

1 Like

Sorry for the late response. I do remember seeing this post and wanting to respond but never getting around to it… I just remembered now while browsing the Lua Chat System article.

I recall this issue as well, the channel tab hangs around when players leave the channel but it’s in all respects “disabled”. You will want to use SetMainChannel to force the user to select a different channel. You’ll notice that this is also used in other cases like entering team or whisper chat when prefixing your message with the relevant command (/t, /w). In fact, the channel bar buttons specifically set the main channel. Main, in this case, refers to the current talking channel.

Combine the above with ChannelLeft (or use the channel specific version, SpeakerLeft). When the speaker leaves the channel, you can call SetMainChannel to force them back to the default channel or another channel of your choosing. If you use the general channel (All), then you can pass All as the channel name and this’ll force players back to global chat.

Depending on my case I may preference one or the other.

local function speakerLeft(speakerName)
    local speaker = ChatService:GetSpeaker(speakerName)
    if speaker then
        speaker:SetMainChannel("All")
    end
end

local function channelLeft(channelName)
    speaker:SetMainChannel("All")
end

This should clear the left channel from the tabs since, if I recall correctly, the channel tab doesn’t clean itself up until you switch channels. Feel free to give that a try.

@colbert2677 are you going to get around to adding these yet considering it’s public now? Not sure if chat commands are documented on DevHub yet (it’s not)

1 Like

i forgot :laughing:

I’ll add the properties now and check if there are any additional information changes to be made. Thank you for the reminder!

EDIT: The changes are now in as Display Name Settings. I’ve also additionally added section headers that users can jump to via a table of contents at the top (no return buttons yet?) and an additional new setting that was added, MaxChannelNameCheckLength. This seems to be the new property that enforces how many characters a channel name can be, whereas MaxChannelNameLength is now used to determine how many characters will show in a button in the channel bar before it gets truncated.

Marking as solution for a while.

2 Likes

Does anyone know how to make it where the All channel Tab Disappear but the Chat Box doesn’t look weird? I have ShowChannelTabs enabled because I want my Staff Chat to Show if they are a certain rank in the group but if they aren’t it returns to global chat for that player but the issue is that the All Tab is still at the top.