TextService function ALWAYS returning errorMessage, how can I fix this?

Firstly the original title was: :GetNonChatStringForBroadcastAsync() function ALWAYS returning errorMessage, how can I fix this? But Roblox Deems this Unclear even though it’s more specific than the current one.

I want to filter a textbox so I don’t get banned. But every single time the script tries to filter it, it always returns the ErrorMessage. Does anyone know why?

Code:


image

image

Local:
image
Output:
image

The code was even based on an Official Roblox Tutorial.

FYI just post your code instead of screenshots of your code.

If you were to output the errorMessage variable you would see the issue.

Is your text parameter of filter a string or a TextFilterResult? You didn’t post enough code.
It appears to be a string because you are reading the Text property of an instance. GetNonChatStringForBroadcastAsync is a method of TextFilterResult which is returned when you make a FilterStringAsync call.

That was all the code but I fixed it because of this nice open sourced game.

And that also explains it aswell.

1 Like

If that is all the code then the issue is:

Take another look at the article you posted.

Example usage of `GetNonChatStringForBroadcastAsync` from the article you posted.

You can see that they’re using a textObject as the parameter to their getFilteredMessage function.

-- Script
 
local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local sign = game.Workspace.Sign
local signTop = sign.Top
local signSurfaceGui = signTop.SurfaceGui
local signLabel = signSurfaceGui.SignLabel
 
local setSignText = ReplicatedStorage.SetSignText
 
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)
		signLabel.Text = filteredText
	end
end
 
setSignText.OnServerEvent:Connect(onSetSignText)