Help with Text Filtering a Player's In-game Bio

The output says:

Error filtering text: whatever text is being filtered goes here : Unable to cast Instance to int64 - Server - ChangeBio:11

The “Text” value that comes from the local script is the text from a textbox where a player can enter their new in-game bio

local Players = game:GetService("Players")
local Event = game.ReplicatedStorage.Profile.ChangeBio
local TextService = game:GetService("TextService")

Event.OnServerEvent:Connect(function(player,Text)
	local filteredText = ""
	local success, errorMessage = pcall(function()
		filteredText = TextService:FilterStringAsync(Text,player)
	end)
	if not success then
		warn("Error filtering text:", Text, ":", errorMessage)
		-- Put code here to handle filter failure, I got this off the dev page and i'm not sure what code to put here, i have been trying to get text filtering to work for a while now and just can't figure it out even with all the stuff i read
	end
	player.Bio.Value = filteredText -- I have a string value in the player to store their bio
	print(filteredText)
end)

Looking at: TextService:FilterStringAsync
I can see that it expects the UserId (int64) and not the player instance. Try sending it player.UserId as a parameter instead :wink:

1 Like

now it says

ServerScriptService.Profile.ChangeBio:14: invalid argument #3 (string expected, got Instance) - Server - ChangeBio:14

You should try tostring(player.UserId)

That’s because the second value the pcall() function returns is an error instance. Check out Programming in Lua : 8.4 for more details. Try using errorMessage.code instead. (might have to call tostring() on the code, idk if it returns a string or if a string is demanded)

can you tell me why i need to have the player’s user id in the first place? i’m not the best at coding. sry

Looking at TextService:FilterStringAsync if you scroll down to “Parameters” you can see the second parameter is called “fromUserId” and next to it you can see the datatype it uses (int64). Next to that you also have a brief explanation on what it is and what it’s used for.

Roblox has made this function and needs the parameters for it to work correctly.

Because, text/numbers are filtered depending on the users’ account settings/age. The UserId is a unique number sequence associated with only that account.

Edit: If everyone in the server can see the text I suggest using Chat:FilterStringForBroadcast

1 Like

ok, so im lost, any ideas on what i can put in this part of the script? then the filtered text will become “FilteredText”

local Event = game.ReplicatedStorage.Profile.ChangeBio

Event.OnServerEvent:Connect(function(player,Text)
	-- ???
	player.Bio.Value = FilteredText
	print(FilteredText)
end)

It’s just the parameters of the function. It follows as:
FilterStringAsync(string stringToFilter, int64 fromUserId, Enum.TextFilterContext textContext)

1 Like

ok, I got it working and when the text isn’t allowed it just puts #s which is what i wanted. thx for y’alls help

local Event = game.ReplicatedStorage.Profile.ChangeBio

Event.OnServerEvent:Connect(function(player,Text)
	local FilteredText = game:GetService("Chat"):FilterStringForBroadcast(Text, player)
	player.Bio.Value = FilteredText
	print(FilteredText)
end)

no errors in output anymore

local Event = game.ReplicatedStorage.Profile.ChangeBio

Event.OnServerEvent:Connect(function(player,Text)
local message = player.Bio.Value
	local FilteredText = game:GetService("Chat"):FilterStringForBroadcast(message, player)
	player.Bio.Value = FilteredText
	print(FilteredText)
end)