I have this code, that used to work. I added filtering, so it’s safe. I think everything should work there, but I get a nil. I tried words that I know will get blocked, and words that won’t. Nothing is in the console.
Server-side
local event = game.ReplicatedStorage:WaitForChild("Intercom")
event.OnServerEvent:Connect(function(p, text)
local TextService = game:GetService("TextService")
local filteredText = ""
local success, errorMessage = pcall(function()
filteredText = TextService:FilterStringAsync(text, p.UserId)
end)
if not success then
warn("Error filtering text")
-- Put code here to handle filter failure
end
event:FireAllClients(filteredText)
end)
I’m not sure why it isn’t working, really. The return nil, meaning the call itself might be failing, though you did set up some sort of error detection.
Maybe check out the creator documentation for TextService and see if you can figure it out yourself?
I now have this code i copied from Roblox dev docs. Now it shows the text, but doesn’t filter it.
local event = game.ReplicatedStorage:WaitForChild("Intercom")
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)
event:FireAllClients(filteredText)
end
end
event.OnServerEvent:Connect(function(p, text)
onSetSignText(p, text)
end)```
I might’ve figured it out. Filtering doesn’t work in Studio, you have to test it in experience.
local event = game.ReplicatedStorage:WaitForChild("Intercom")
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)
event:FireAllClients(filteredText)
end
end
event.OnServerEvent:Connect(function(p, text)
onSetSignText(p, text)
end)```