FilterStringAsync returning as an instance instead of string

So I am currently attempting to filter a string, but for some reason, the string returns as an instance.

Filter Code:

	local success, msg = pcall(function()
		currentName = textService:FilterStringAsync(Name, plr.UserId)
	end)

The name variable is already a string.

Code where I set the text:

plr:SetAttribute('RestaurantName', currentName)

The error is: Instance is not a supported attribute type.

plr:SetAttribute('RestaurantName', currentName:GetNonChatStringForUserAsync())

TextService:FilterStringAsync() returns a TextFilterResult which has 3 functions that actually do return a string

You need to change your code to handle the return value correctly, use GetChatForUserAsync to retrieve the filtered string, and you should assign the filtered name to currentName and handle any potential errors appropriately, here’s how you’d go about doing that Xx

local success, filteredName = pcall(function()
    return textService:FilterStringAsync(Name, plr.UserId):GetChatForUserAsync(plr.UserId)
end)

if success then
    currentName = filteredName
else
    warn("Failed to filter the name: " .. filteredName)
    currentName = Name 
end

plr:SetAttribute('RestaurantName', currentName)

So I have used your new code, but it does not seem to be filitering the string. (Btw I am also setting a textlabel to the currentName text later on in the script.) Code:

	local success, filteredName = pcall(function()
		return textService:FilterStringAsync(Name, plr.UserId):GetChatForUserAsync(plr.UserId)
	end)

	if success then
		currentName = filteredName
	else
		warn("Failed to filter the name: " .. filteredName)
		currentName = Name 
	end

	plr:SetAttribute('RestaurantName', currentName)

I added a warn(‘Filitered name’) when the name is successfullt filitered but its not being filitered.

I was able to find out what was causing it (I forgot to post this) so basically I did not know the text did not filter in roblox studio, so I went in game and tested it. It worked perfectly fine.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.