The script below is my code using the legacy TextService, and essentially, this just returns an empty string since it’s deprecated.
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
return function (context, text)
local filterResult = TextService:FilterStringAsync(text, context.Executor.UserId, Enum.TextFilterContext.PublicChat)
for _, player in ipairs(Players:GetPlayers()) do
if Chat:CanUsersChatAsync(context.Executor.UserId, player.UserId) then
context:SendEvent(player, "Message", filterResult:GetChatForUserAsync(player.UserId), context.Executor)
end
end
return "Announced: " .. text
end
How would I modify the code now, I did some light resource, but I’m just really confused and could not really find anything. Could anyone provide assistance on how I can achieve filtering with the new TCS?
It depends on what Kind of Filtering you want to do. I highly recommend you read more on the roblox doc, like here, if you need more help understanding Text Filtering! Here are the 2 options you can choose from:
:GetNonChatStringForBroadcastAsync() is when you are filtering text for EVERYONE to see. This could be used in many ways, and the most commonly used one when using user input to display publicly.
:GetNonChatStringForUserAsync() is when you are filtering for One person or User. This will consider the persons age, and other details and may be more or less strict.
All of this to say, either method is similar in their implementation as seen below:
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
return function (context, text)
local filterResult = TextService:FilterStringAsync(text, context.Executor.UserId, Enum.TextFilterContext.PublicChat)
for _, player in ipairs(Players:GetPlayers()) do
if TextService:CanUsersChatAsync(context.Executor.UserId, player.UserId) then
context:SendEvent(player, "Message", filterResult:GetNonChatStringForBroadcastAsync(), context.Executor) -- Change this if GetNonChatStringForBroadcastAsync is not the one you want.
end
end
return "Announced: " .. text
end
If you are looking for something to replace :GetChatForUserAsync() exactly, I could not find an option that matches it perfectly 1 for 1, as it seems to me and the research I did that the two methods above are the only supportive ones, based off of posts like these, However you should be able to use the 2 methods above to hopefully fit your needs.