Help with filtering text

So I am currently working on a Lua console, and I wanted to filter the text label that is the output, (It’s global, mostly because it’s funny to talk to other people) but I couldn’t find a way to do this, I have made some basic scripts to do this, but they never worked.


Server script, inside of Workspace (For now):

game.ReplicatedStorage.FilterOutputEvent.OnServerEvent:Connect(function(plr,message,filteredMessage)
	filteredMessage = game:GetService("Chat"):FilterStringForBroadcast(message, plr)
	return filteredMessage
end)

Local script inside of a text label:

local plr = game.Players.LocalPlayer

coroutine.wrap(function()
	game.ReplicatedStorage.CurrentLine:GetPropertyChangedSignal("Value"):Connect(function()
		local text = game.ReplicatedStorage.CurrentLine.Value
		local message = script.Parent.Text
		local filteredMessage = ""
		
		script.Parent.Text = game.ReplicatedStorage.FilterOutputEvent:FireServer(message,filteredMessage)
	end)
end)()

I have never did anything with filtering, so I have no idea about good practices, and how to actually filter text.

After a simple print function into the console, I get an error:

image

Any help is appreciated!

I recommend reading this DevHub article on chat filtering. I’m not an expert in chat filtering and custom chat boxes as I haven’t had a need for it yet, but it looks like you should wrapping your filtering function in a pcall.

Also, not sure why the text variable is needed in the local script because it doesn’t look like you’re doing anything with it.

Your error message means that your 3rd argument was nil, and that there was never a string.

1 Like

I completely reworked my code after looking around, here is the new code:

Server script:

local TextService = game:GetService("TextService")

coroutine.wrap(function()
	game:GetService("LogService").MessageOut:Connect(function(Message)
		
		game.ReplicatedStorage.CurrentLine.Value = Message
	end)	
end)()

game.ReplicatedStorage.FilterOutputEvent.OnServerEvent:Connect(function(plr,message)
	local filteredMessage = TextService:FilterStringAsync(message,plr.UserId)
	local fullMessage = filteredMessage:GetNonChatStringForBroadcastAsync()
	
	print(filteredMessage)
	print(fullMessage)
	
	game.ReplicatedStorage.CurrentLine.Value = fullMessage
end)

Local script:

local plr = game.Players.LocalPlayer

coroutine.wrap(function()
	game.ReplicatedStorage.CurrentLine:GetPropertyChangedSignal("Value"):Connect(function()
		local text = game.ReplicatedStorage.CurrentLine.Value
		local message = script.Parent.Text
		
		game.ReplicatedStorage.FilterOutputEvent:FireServer(message)
		task.wait(0.25)
		script.Parent.Text = game.ReplicatedStorage.CurrentLine.Value
	end)
end)()

The issue with the code, is that fullMessage is a blank string for some reason, I can’t figure out why though. Should I try the script in game?

Output:

image

Put a print statement after you’ve created the filteredMessage variable and see what it says.

Also, I’ve read that filtering doesn’t work in Studio, so make sure you test it in a live game.

1 Like

The filteredMessage prints Instance, and the fullMessage prints a blank string. I’ll go test the game in a live server to see if that works.

So I tested it in game, and I got this:

image

I disabled use of HTTP requests in my game, and I made the game kick you if you try to use HttpService in the console, so I don’t really know why this is Happening.

RemoteEvents does not return anything. I think you are looking for: RemoteFunction | Roblox Creator Documentation

Roblox’s filtering process is done internally which I’m pretty sure means Roblox has to use some filtering software of their own which is on another website. The article I linked mentioned that. Try allowing http requests. I’m not sure how anyone besides you would be able to send http requests through the dev console because it should be only available to you.

The entire game IS a console.

Anyways, I’ll try enabling HTTPS requests, HttpService is still blocked in custom console I made, so everything should be fine.

1 Like

Okay something really weird happened, at first I just got the same error, but I tried to input another print command, and it showed the normal string, then the filtered string into the custom output with a slight delay, which I think I know where the issue lies at, but the error appearing when you type something in at first, is just unexpected.

image

EDIT: I tried to print “hi” in my custom console, and the output flashed between “hi” and this filtered error:

EDIT 2: I might try to find a way to filter only code inputted from the console, and not errors.

The filtered message appearing after the actual message is the error. The error points to line 11 which is: local filteredMessage = TextService:FilterStringAsync(message,plr.UserId).

Are you still testing in a live game?

1 Like

I am testing in a live game, I’ll go and look at line 11.

50-30 ch + ars

I made an infinite loop. I tried to print the message that is being sent from the client, on the server, and it just prints the message, then a blank string, then the message again, again and again again, forever.

EDIT: I think I found the problem, in the server script, there is a section that changes a value called “CurrentLine” to the whatever appears in the output. In the section that filters the output, it changes the value of “CurrentLine” to the filtered text, that would be fine and all, but in the local script that actually shows the output to the player, it detects when the value of “CurrentLine” changes, and when it does, it fires a remote event to filter the text, which then changes the value of “CurrentLine”, which makes the local script fire the remote event again, and so on, and so forth.

1 Like

I’ve got classes in a couple of minutes. I’ll keep looking later when I get home to my computer.

I would just keep browsing the devforum and others articles for solutions for now. Really sorry.

1 Like

The game is singleplayer only at the moment, mostly because of the unfiltered output, so it wouldn’t be that bad if left the output unfiltered. Thank you for your help!

1 Like