I made a text filtering system for a textbox and the way it is set up, I want only the appropriate text from the textbox to be “accepted” if you will, and so then I can do something further.
I’ve played around with my code where I thought I implemented some code that would check whether the text is appropriate or not but it doesn’t seem to work.
I looked on DevForum and found some posts on this issue but they didn’t help me.
This is code from my client script when the player clicks on the button that sends the text to the server to be examined by TextService in the server script.
-- This is an example Lua code block
local fun = game.ReplicatedStorage:WaitForChild("Filter") --Remote Function
local function onClick() -- Function for clicking button
local message = script.Parent.Parent.NameYourTeamTb.Text --Gets the Textbox's text
local FilteredTxt = fun:InvokeServer(message) --I passed the text into the remote function
if FilteredTxt then
script.Parent.Parent.NameYourTeamTb.Text = FilteredTxt --NameYourTeamTb is the textbox
wait(5)
script.Parent.Parent.NameYourTeamTb.Text = ""
end
if FilteredTxt == "Allowed" then
print("Text allowed")
end
end
script.Parent.MouseButton1Click:Connect(onClick)
Here is what the server script looks like. It contains everything that makes the text filtering actually work. The if statement after I declared the pcall function is what I implemented to try checking for if the filtering failed or didn’t work when the text is fine and doesn’t need any filtering. I figured it would have warned me in the console but nothing happened…
local fun = game.ReplicatedStorage:WaitForChild("Filter")
local ts = game:GetService("TextService")
fun.OnServerInvoke = (function(player, textToFilter) --textToFilter is my text from textbox
local success, er = pcall(function()
local filteredTextResult = ts:FilterStringAsync(textToFilter,player.UserId)
return filteredTextResult:GetNonChatStringForBroadcastAsync() --Is this line even needed?
end)
if not success then
warn("Error filtering text", er)
return "Allowed"
end
end)
If someone could help me out with my problem that would be greatly appreciated. Don’t hesitate asking me further questions.