Hello, I tried to make a string filtering system for my game. My goal is making a function that returns a bool value. If this string filtering to playes this bool value should be true else bool value should be false
The issue is the bool value is always true. I think I made a mistake in one of scripts. Btw I don’t know how to use filtering systems and I didn’t find a good tutorial on youtube.
Here is scripts:
First script is a local script inside StarterGui/ComputerGui/Background
local UserInputService = game:GetService("UserInputService")
local TextService = game:GetService("TextService")
local player = game:GetService("Players").LocalPlayer
local function textFiltered(text)
return game.ReplicatedStorage.FilterStringFunction:InvokeServer(text)
end
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.Return and script.Parent.BoxFrame.TextBox.Text ~= "" then
script.Parent.TuturialFrame.Visible = false
local texttofilter = script.Parent.BoxFrame.TextBox.Text
if textFiltered(texttofilter) then
print("text filtered")
else
game.ReplicatedStorage.SendMessageEvent:FireServer(script.Parent.BoxFrame.TextBox.Text)
script.Parent.BoxFrame.TextBox.Text = ""
wait(0.35)
script.Parent.BoxFrame.TextBox:CaptureFocus()
end
end
end
UserInputService.InputBegan:Connect(onKeyPress)
Also there is remote function inside replicated storage
This is other script in ServerScriptService
local TextService = game:GetService("TextService")
local FilterStringFunction = game:GetService("ReplicatedStorage").FilterStringFunction
FilterStringFunction.OnServerInvoke = function(player, text)
return TextService:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat) ~= text
end
Why this function always returns true. Btw I don’t want filtered. I need a function that returns is this string filtered string or not but I don’t know how to make this also I tried here.
This filtering system for another thing not chat. I tried to make a game that you can speak with AI. You can type your message in textbox so I need a filtering system to prevent bad words.
local TextService = game:GetService("TextService")
local FilterStringFunction = game:GetService("ReplicatedStorage").FilterStringFunction
local function getTextObject(message, fromPlayerId)
local textObject = nil
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 = nil
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
local function isTextValid(player, text)
local messageObject = getTextObject(text, player.UserId)
local filteredText = ""
filteredText = getFilteredMessage(messageObject)
return filteredText ~= text
end
FilterStringFunction.OnServerInvoke = function(player, text)
return isTextValid(player, text)
end