Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] Text being filtered for no reason in textService:FilterStringAsync?

EDIT 2: Turns out filtering only works in normal roblox, not in studio. thanks to https://devforum.roblox.com/t/how-to-use-the-filterstringasyncs-yield-functions/81735

My working script is this:




textService = game:GetService("TextService")

game.ReplicatedStorage.NameChange.OnServerEvent:Connect(function(Player, Text)
	local FilteredText = ""
	local suc,err = pcall(function ()--filters name input
			FilteredText = textService:FilterStringAsync(Text, Player.UserId)
	end)
	
	print(Text)
	print(FilteredText)
	FilteredText = FilteredText:GetNonChatStringForBroadcastAsync()
	print(FilteredText)
		if not suc then--if filtering failed, name player the error
			Player.Character.Head.BillboardGui.TextLabel.Text = "#"
			print('filtered')
		end
		if suc then
			Player.Character.Head.BillboardGui.TextLabel.Text = FilteredText
			print("Success")
		end
end)

	

EDIT: So I ran this in the console (warning it contains a swear word)

print(game.TextService:FilterStringAsync('shit', game.Players.UNBANhappyniceguy5.UserId):GetNonChatStringForBroadcastAsync())

and it just printed the swear word uncensored... am I doing something wrong?

ORIGINAL: So I have a custom role playing name script, but whatever I write gets filtered. Here's the script


textService = game:GetService("TextService")

game.ReplicatedStorage.NameChange.OnServerEvent:Connect(function(Player, Text)
	local FilteredText = ""
	local suc,err = pcall(function ()--filters name input
			--name = chatService:FilterStringForBroadcast(Text,Player)
		
			print("attempt")
			FilteredText = textService:FilterStringAsync(Text, Player)
			print(FilteredText)
	end)
	print(suc)
		if not suc then--if filtering failed, name player the error
			Player.Character.Head.BillboardGui.TextLabel.Text = "#"
			print('filtered')
		end
		
end)

It seems to not print the filtered text at line 10 so I guess the script is just skipping line 9 which is FilteredText = textService:FilterStringAsync(Text, Player)?

This is my first time doing filtering so I have no idea what's wrong.

9 comments

0

Actually print the exception message at line 5. Probably something happened. Also, when you want to refer to a specific line, refer to the line relative to this code block, because line 13 and line 12 are not what you say it is.

0

oh sht, didn't notice the code block thing, one sec let me fix it.

0

pls no swearing, incomplete or censored or not

0

Ok sorry. What do you mean "Actually print the exception message at line 5."?

0

print(err)

0

Unable to cast Instance to int64

0

Turns out I had to make it Player.UserId, but it still doesn't work and just makes it pass the filter every time

0

When I do print(FilteredText) it prints "Instance" instead of string

0

You should mark your post as solved by putting [solved] at the start of your title.

2 answers

Found an answer here

But what really ticked me off is your use of pcall.

You don't need to pass a function literal, you can just pass a reference to the FilterStringAsync method directly.

Maybe this will miraculously work and it's just something you did wrong and you didn't see it

local textService = game:GetService("TextService") -- pls use local variable

local successful, result = pcall(textService.FilterStringAsync, textService, Text, Player)

if successful then
	local result_success, filtered = pcall(result.GetNonChatStringForBroadcastAsync, result)
	Player.Character.Head.BillboardGui.TextLabel.Text = successful and filtered or "#"
end

If pcall returns true (it always returns a boolean first), then the return values after are the return values of the function passed. pcall also takes multiple arguments, not just a function. The arguments after the function are the arguments to the function passed. a:b(...) is syntactic sugar for a.b(a, ...) so textService is being passed as argument there so Lua knows what to call the method on

3 comments

0

It doesn't seem to work, I get this error: ServerScriptService.Name Change:15: Expected ')' (to close '(' at line 14), got 'Player'

0

look at my edit, is that normal?

0

finally got it to work, thanks for trying.

This discussion is preserved as it was. New answers, comments, and votes are closed.