Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to filter a custom chat?

Asked by 11 months ago

I want to know the name of the function used to filter text, aka tagging chats, and how to use to the function for my custom chat.

0
It's the 21st century. Google it genius. Ziffixture 6913 — 11mo
0
jeez Trampyling 43 — 11mo

1 answer

Log in to vote
1
Answered by 11 months ago
Edited 11 months ago

You can use TextService:FilterStringAsync() then use TextFilterResult:GetChatStringForUserAsync().

-- in the part of your script where message will be sent
local TextService = game:GetService("TextService")
local Result = TextService:FilterStringAsync(Message, Speaker.UserId) -- "Message" is the string of the speaker's message; "Speaker" is the Player instance of the player that wrote the message

local Players = game:GetService("Players")
for _, Player in ipairs(Players:GetPlayers()) do -- gets every player in the server
    if Player.Name ~= Speaker.Name then -- if Player is not Speaker
        local success, filteredMessage = pcall(Result.GetChatForUserAsync, Result, Player.UserId) -- Result:GetChatForUserAsync() but wrapped in pcall (protected call) to avoid errors that will break the script

        if success then -- no errors
            -- send the filtered message
        end
    end
end
-- the rest of the script

Make sure the script is a normal script or else it won't work. You have to get Speaker and Message somehow, probably by using a RemoteEvent. In sending the message, you should use RemoteEvent, too, to respect the receiver's chat filter settings.

As what @Ziffixture said, it is correct that you should search your problem before posting it here to avoid spam. I searched it and there's a ton of results with the same problem as yours and they are solved. Next time, search before posting, ok? :)

0
tysm dude, also i will search it up next time, thanks XD Trampyling 43 — 11mo
Ad

Answer this question