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.
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 ########.
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)