Problem with BubbleChat in Part and Text Filtering

Hey everyone,
I’ve written a script that spawns a local part, and copies the text output from the LocalPlayer in that separated part, that has a bubble like this:

image

The purpose of doing this, is so you can see the bubble chat when you’re in first person (This is the third person toggle button to show my issue)
The problem is, that part displaying the bubble is unfiltered and doesn’t distiguishes between “/whisper” or “/e…msg” and similar. But my main problem here is the fact that it’s not filtering. (Though I would appreciate if you could help me with the second one)

For the filtering problem, I’ve tried looking at the Text and Chat Filtering post in the DevHub, but I can’t get my head around it. I’ve also looked up older DevForum posts and nothing. And yes, I’m testing in-game and not in Studio, I know it doesn’t filters there.

Here’s the relevant part of my code that duplicates the Client’s chat:

-- [ DUPLICATE CLIENT CHAT INTO BUBBLE PART]

game.Players.LocalPlayer.Chatted:Connect(function(msg)
	ChatService:Chat(part, msg)
end)

As for the second issue I have, it doesn’t seems to identify when to not spawn a bubble, like so:
image
I have tried to use string.match to identify wherever or not to duplicate the chatting, but the way I did it doesn’t works.
I don’t have the exact code I wrote for that as I discarded it quite quickly, but here’s what I remember I tried to do:

-- [ DUPLICATE CLIENT CHAT INTO BUBBLE PART]

game.Players.LocalPlayer.Chatted:Connect(function(msg)
	if not msg:Match("/e")..msg or ("/e") or ("/w") or ("/whisper") or ("/t") then
		ChatService:Chat(part, msg)
else
	end
end)

That’s about it, I’m probably missing something obvious but I’ll learn eventually, got into coding just a few months ago, thanks in advantage for anyone helping!

If I understood this correctly, it isn’t filtering because you aren’t using FilterStringAsync. (I may be wrong about this, I rarely filter things.)

EDIT: Turns out it was as simple as doing this…

		game.Players.LocalPlayer.Chatted:Connect(function(msg)
			local FilteredString = ChatService:FilterStringForBroadcast(msg,plr)
			wait(0.1)
			ChatService:Chat(game.Workspace.bubblepart, FilteredString)
		end)

Thanks for your help!

Heiwa grandbaby.

local PS = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local Player = PS.LocalPlayer
local Chat = game:GetService("Chat")
local Events = RS:WaitForChild("DefaultChatSystemChatEvents")
local DFM = Events:WaitForChild("OnMessageDoneFiltering")

function find(pn)
    for i,k in pairs(PS:GetPlayers()) do
        if k.Name == pn then
            return k
        end
    end
end

DFM.OnClientEvent:connect(function(data, channel)
    local speaker = find(data.FromSpeaker)
    if (not speaker) or data.FromSpeaker ~= Player.Name then
        return
    end
    --speaker is the person that said the message.
    --data.Message is the filtered message.
    Chat:Chat(workspace.TestPart,data.Message,Enum.ChatColor.White)
end)

It accesses the events created by the roblox chat modules and scripts
and listens for the finished filtered message event, this should work much better for what you are trying to do!

1 Like