How Do I Actually Filter Chat Messages When They Are Displayed On Text Labels?

It’s a battle royale game and I want the players’ text messages to appear above them (Which the game does fine), it just needs to apply the chat filter to the messages, because I don’t know if you know this, but little timmy should not be able to curse and have everyone see that.

(Most of the stuff below doesn’t matter)

game:GetService(“Players”).PlayerAdded:Connect(function(player)
local chats = 0
local last = Instance.new(“StringValue”)
last.Name = “LastMessage”
last.Parent = player
player.Chatted:Connect(function(message)
if player.Character then
if player.Character:FindFirstChild(“ChatBar”) then
– I’ve been putting the filtering stuff here
last.Value = message
local text = player.Character.ChatBar.text
text.Text = “”
text.TextTransparency = 0
for i = 1, #message do
if last.Value ~= message then return end
if player.Character then
if player.Character:FindFirstChild(“BusTeleporterScript”) then
if player.Character.BusTeleporterScript.Enabled == false then
local parts = player.Character:GetChildren()
for _, part in pairs(player.Character:GetChildren()) do
if part.Name == “Fishbrella” then
if part:IsA(“Model”) == false then
break
end
end
end
if player.Character:FindFirstChild(“HumanoidRootPart”) then
local audio = game.ServerStorage.Sounds.Chat:Clone()
audio.Parent = player.Character.HumanoidRootPart
audio.Name = “ChatSound”
audio:Play()
end
end
else
if player.Character then
if player.Character:FindFirstChild(“HumanoidRootPart”) then
local audio = game.ServerStorage.Sounds.Chat:Clone()
audio.Parent = player.Character.HumanoidRootPart
audio.Name = “ChatSound”
audio:Play()
end
end
end
end
local char = message:sub(i,i)
text.Text = text.Text…char
wait(0.075)
if player.Character then
if player.Character.HumanoidRootPart:FindFirstChild(“ChatSound”) then
player.Character.HumanoidRootPart.ChatSound:Destroy()
end
end
end
chats += 1
wait(5)
chats -= 1
if last.Value == message then
if chats > 0 then return end
repeat
wait(0.025)
text.TextTransparency += 0.1
until text.TextTransparency == 1 or last.Value ~= message
if last.Value ~= message then return end
text.Text = “”
chats = 0
end
end
end
end)
end)

I’ve tried GetNonChatStringForBroadcastAsync() [It supposedly doesn’t work for chat messages], FilterStringAsync() [It needed a player the message was going to], FilterStringForBroadcast() [But of course it only works on the client], and some other methods I forgot about. All of which failed.

Any help is appreciated, and I don’t know how I manage to get myself in these situations where the Roblox AI and Documentations are no help, but I do somehow, and I can’t say I enjoy that.

I don’t see the issue with the methods you listed. Just do the filtering from the client? You could send the message through a remote event and filter it beforehand for each player with TextService | Documentation - Roblox Creator Hub, what I would recommend, or just give everyone the message and filter it client side. Create the textlabel on each client and parent it accordingly.

I don’t want to do it from the client, because anything client sided can be exploited by hackers so some hacker would just come along and ruin it. I’ve just tried a system where I put the player’s chat message on a UI that’s in ServerStorage and then it uses NonChatFilter() or whatever it was called on that and make it the player’s chat message so it works.

You said that these filter methods failed, but where did you test them? If you tested them in Studio, it’s important to note that Studio lacks the Roblox chat filter, and I’ve found that this causes chat filter methods to also not work. I tested this by using TextService:FilterStringAsync and then TextFilterResult:GetNonChatStringForBroadcastAsync(), on Roblox servers it tagged, and in Studio it did not.

Try using the GetNonChatStringForBroadcastAsync() method in game servers instead of studio and lmk the result.

Why would you care if a hacker changes what they see? Each client would do their own filtering, so it wouldn’t matter. If you prefer, you could do what I recommended and filter it from the server.

The server sees it, not just the client. So I would care then.

Yeah I’ve just found that out a while ago and I’m trying something else

1 Like