Can you clear the new roblox chat using a script?

Hello, I’m wondering if there is a way to clear the chat using a script. I have looked at some posts on the Forums; however, what I found was from between 2019-2021 with the old chat system and the code that I found no longer works as the new chat is no longer stored as a ScreenGui inside of PlayerGui in the player.

image

If anyone has any solutions it would be much appreciated so please do reply if you can :slight_smile:

5 Likes

All of the chat commands and methods are now internal and cannot be accessed through normal scripts. You can only use the given APIs to do certain actions now.

From what I’ve seen, there isn’t an exposed API or method that allows you to clear the chat for now. You can only do this with the old chat system.

1 Like

Does forcing the player to chat ‘/clear’ work?

2 Likes

Thanks for the reply! I’ll most likely use the LegacyChatSystem and modify some of the scripts to work with it.

3 Likes

Would say that this script would work, i did not test it yet, but tell me if it works :wink:

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if message:lower() == "/clearchat" then
            for i = 1, 50 do
                game.ReplicatedStorage.DefaultChatSystemChatEvents.SayMessageRequest:FireServer(" ", "All")
            end
        end
    end)
end)

1 Like

It works with the Adonis Admin system, so obviously there’s a way to do it.

1 Like

Unfortunately this didn’t work. Thanks for the reply though :slight_smile:

3 Likes

Np! sorry imma try to make a new one that works.

1 Like

Thanks it’s alr if you aren’t able to though I’m sure I’ll find some solution or compromise in the future if not.

2 Likes

After a lil bit of time, i made this script, i did not test it tho, but if it does work tell me!

local function clearChat()
    local chatService = game:GetService("Chat")
    for _, channel in pairs(chatService:GetChannels()) do
        channel:Clear()
    end
end

clearChat()

this one probably works

1 Like

that’s chatservice
probably wont work since its not compatible with textchatservice

1 Like

Who knows, could work. And sorry if it dosen’t work

1 Like

Unfortunately, it didn’t work as there us no Clear() function for the TextChannels:
Text Channels - Documentation

I did also test it it in studio and it came up with the corresponding error:
image

I also had to modify the code slightly as GetChannels() wasn’t a function and the TextChannels are stored in TextChatService in the new chat system.

1 Like

Sorry did my best there! :confused: Sorry again i thought there was a Clear() function

1 Like

It’s alr it would be ideal if roblox has an easier way to clear the chat such as a Clear() function for text chat service. I might post a feature request as I’m sure there’s a few other people experiencing a similar issue.

1 Like

Since you’re a member, you can’t post a feature request.

1 Like

You can clear chat by calling this on the client:

local TextChatService = game:GetService("TextChatService")

TextChatService.TextChannels.RBXGeneral:SendAsync("/clear")

If you wanted to clear them from the server, you would need to use a RemoteEvent to send a request from the server to the client.

1 Like

Thanks so much! This works perfectly as intended :slight_smile:

pretty much what i said, but with code
oh well

yeah sorry for kinda stealing your solution but i did come up with it before i saw your message (I have been working with TextChatService recently so i knew), and code examples are really important