How to use FilterStringAsync()?

I’ve been messing around with FilterStringAsync() for 3 hours but I can never get it to work?
Here is some errors I’ve been getting:
ServerScriptService.UpdateTag:13: attempt to concatenate local ‘filteredTextResult’ (a userdata value)
" Unable to cast Instance to int64"

Code:

local mps = game:GetService("MarketplaceService")
local ts = game:GetService("TextService")
local rem = rep:WaitForChild("UpdateTag")

rem.OnServerEvent:Connect(function(player, tagText, tagFont, tagColorR, tagColorG, tagColorB, tagStroke, tagBrackets)
	print(tagText)
	local tag = game.Workspace:WaitForChild(player.Name).Head.Nametag.Frame.VIP
	local owns = mps:UserOwnsGamePassAsync(player.userId, 6659891)
	if owns then
		local filteredTextResult = ts:FilterStringAsync(tagText, player, 1)
		if tagBrackets == true then
			tag.Text = "["..filteredTextResult.."]"
		else
			tag.Text = filteredTextResult
		end
		tag.TextColor3 = Color3.fromRGB(tagColorR, tagColorG, tagColorB)
		tag.Font = tagFont
		tag.TextStrokeTransparency = tagStroke
	end
end)

:FilterStringAsync() expects three parameters, the first is the string to be filtered, second is the UserId of the player and third is an optional context enum. You are passing the player instance as the second parameter instead of the UserId, explaining the “Unable to cast Instance to int64” error. Exchange player with player.UserId.

The above method also returns an instance, not a string, which explains the concatenation error ( tag.Text = "["..filteredTextResult.."]" ). Use one of the following functions on the instance to get filtered text: GetChatForUserAsync, GetNonChatStringForBroadcastAsync, GetNonChatStringForUserAsync. They each filter text to a different extent, so make sure to read up on them.

Example:

local ts = game:GetService("TextService")
local text = "hello"
local filteredtext = ts:FilterStringAsync(text, game.Players.byc14.UserId):GetNonChatStringForBroadcastAsync()
print(filteredtext)

image

8 Likes

If I still right an word that normally gets tagged it still comes up?

Side effect of testing in a studio environment. Deploy to a live game and it will correctly filter.

image

Edit: censored text.

7 Likes