Censoring text not working

My script to censor text is not working. First script:

local RS = game:GetService("ReplicatedStorage")
local fSS = RS:WaitForChild("filterStringService")
local finishButton = script.Parent.finish

local finalText = script.Parent.text

finishButton.MouseButton1Click:Connect(function()
	local text = script.Parent.text.Text
	local textI, filtered = fSS:InvokeServer()
	
	if filtered == false then
		finalText.Text = text
	else
		finalText.Text = "########"
	end
end)

Second script:

local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TextService")

local fSS = RS.filterStringService

fSS.OnServerInvoke = function(player, text)
	print("yeeeeet")
	local filteredI = TS:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat)
	local filteredS = filteredI:GetNonChatStringForUserAsync(player.UserId)
	print("yeeeeet")
end

It says “Argument missing 1 or nil” on lines 8 & 9 of the second script.

You need to give the argument:
local textI, filtered = fSS:InvokeServer(text)

You also need to switch the text variable later to textI

finalText.Text = textI

Works, but something else isn’t working now. I printed finalText at the end of the first script and it just said “text”. It needs to say either the word or ########.

As I can see here

finalText variable contains an instance so try printing finalText.Text instead

No final text isn’t a instance/parent of one. It’s just for testing and later when I set the real text. I have another script making the text.

player = game.Players.LocalPlayer

finishButton = player.PlayerGui.write.finish
textBox = player.PlayerGui.write.text

ReplicatedStorage = game:GetService("ReplicatedStorage")
createNote = ReplicatedStorage:WaitForChild("createNote")

noteAsset = ReplicatedStorage:WaitForChild("Note")

--Open Note Creation
createNote.OnClientEvent:Connect(function()
	finishButton.Visible = true
	textBox.Visible = true
end)

--Finish Note
finishButton.Activated:Connect(function()
	finishButton.Visible = false
	textBox.Visible = false
	local note = noteAsset:Clone()
	note.Handle.textHolder:WaitForChild("writtenText").Text = script.Parent.text.Text
	
	note.Parent = player.Backpack
end)

You might be right, but the . gets an error.

I think you forgot to put a return here which would return these variables

This?

fSS.OnServerInvoke = function(player, text)
	print("yeeeeet")
	local filteredI = TS:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat)
	local filteredS = filteredI:GetNonChatStringForUserAsync(player.UserId)
	print("yeeeeet")
	return filteredI, filteredS
end

Nothing change when I tried that.

Are you trying this in studio? Roblox’s chat filter does nothing if you are in studio.

still doesnt work in the real game.

I did this super quick, and it works, but only in a real game, not in studio:

-- client
local remote = game.ReplicatedStorage.RemoteFunction

local textBox = script.Parent.TextBox
textBox.FocusLost:Connect(function()
	local text = textBox.Text
	local ff = remote:InvokeServer(text)
	print(ff)
end)
-- server
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TextService")

local fSS = RS.RemoteFunction

fSS.OnServerInvoke = function(player, text)
	print("yeeeeet")
	local filteredI = TS:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat)
	local filteredS = filteredI:GetNonChatStringForUserAsync(player.UserId)
	print("yeeeeet")
	return filteredS
end

You’ll need to return your filteredI and filteredS in the InvokeServer function, otherwise the client receives no information back.

You also need to pass the InvokeServer function an argument for the text when you invoke it, otherwise it will not know which text to filter.

You should also note that the chat filter does not apply in Roblox Studio, so you’ll have to play in an actual server to see the result.


Your server code will look something like below, which will return one value - the filtered result. If the text was not filtered, it will simply return the same text. However, if it was filtered, it will return the filtered version (e.g. “######”).

-- Services
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TextService")

-- Variables
local fSS = RS:WaitForChild("filterStringService")

-- On Server Invoke
fSS.OnServerInvoke = function(player, text)
    local filteredI = TS:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat)
    local filteredS = filteredI:GetNonChatStringForUserAsync(player.UserId)
    return filteredS
end

Your client code will look something like below, which passes text as an argument to the RemoteFunction, and uses the value it returns to display the final text.

-- Services
local RS = game:GetService("ReplicatedStorage")

-- Variables
local fSS = RS:WaitForChild("filterStringService")
local finishButton = script.Parent.finish
local finalText = script.Parent.text

-- Finish Button Click
finishButton.MouseButton1Click:Connect(function()
    local text = script.Parent.text.Text
    local filteredText = fSS:InvokeServer(text)
    finalText.Text = filteredText
end)

Some resources you may find useful:
How do I use TextService:FilterStringAsync() | Roblox Developer Forum
TextService | Roblox Creator Documentation
RemoteFunction | Roblox Creator Documentation

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