My string isn't filtering, how do I fix this?

So I followed this example [example 2] from roblox developer hub and it doesnt seem to work for me. Am I doing something wrong?

I’m trying to filter a string that is displayed on a surface gui in workspace.

local rs = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")

local function getTextObject(message, fromPlayerId)
	local textObject
	local success, errorMessage = pcall(function()
		textObject = TextService:FilterStringAsync(message, fromPlayerId)
	end)
	if success then
		return textObject
	elseif errorMessage then
		print("Error generating TextFilterResult:", errorMessage)
	end
	return false
end

local function getFilteredMessage(textObject)
	local filteredMessage
	local success, errorMessage = pcall(function()
		filteredMessage = textObject:GetNonChatStringForBroadcastAsync()
	end)
	if success then
		return filteredMessage
	elseif errorMessage then
		print("Error filtering message:", errorMessage)
	end
	return false
end

-- Fired when client sends a request to write on the sign
local function onSetSignText(player, text)
	if text ~= "" then
		-- Filter the incoming message and send the filtered message
		local messageObject = getTextObject(text, player.UserId)
		local filteredText = ""
		filteredText = getFilteredMessage(messageObject)
		ui.TextLabel.Text = filteredText
	end
end

rs.EditBooth.OnServerEvent:Connect(function(plr, text2)
	onSetSignText(plr, text2)
end)

there are no errors in output.

1 Like

Maybe break down that wall-o-code with all the objects and scripts I don’t even have into a small code segment that just deals with your problem. Then post that …

1 Like

Strings will not filter in studio, and no errors will appear. Are you doing this in studio?

4 Likes

Sorry, just realized my mistake. I was doing this in studio which caused it to not work.

1 Like

I’m bumping this because there’s a lot of people we can potentially help.

local strig = game.TextService:FilterStringAsync(typeof(userMessageString) == "string" and userMessageString,player.UserId,Enum.TextFilterContext.PublicChat):GetNonChatStringForUserAsync(player.UserId)
local likeAgesStrig = game.TextService:FilterStringAsync(typeof(userMessageString) == "string" and userMessageString,player.UserId,Enum.TextFilterContext.PublicChat):GetChatForUserAsync(player.UserId)
local allAgesStrig = game.TextService:FilterStringAsync(typeof(userMessageString) == "string" and userMessageString,player.UserId,Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync(player.UserId)

print(strig,likeAgesStrig,allAgesStrig)

Testing this in studio should totally present the final product, instead of an unfiltered result every time. Everyone’s breaking the rules if they have to publish the game and swear at it to see the results.