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
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.
oh sht, didn't notice the code block thing, one sec let me fix it.
pls no swearing, incomplete or censored or not
Ok sorry. What do you mean "Actually print the exception message at line 5."?
print(err)
Unable to cast Instance to int64
Turns out I had to make it Player.UserId, but it still doesn't work and just makes it pass the filter every time
When I do print(FilteredText) it prints "Instance" instead of string
You should mark your post as solved by putting [solved] at the start of your title.