Writing a name system and i need to filter text becuz its mandatory been stuck on this for a while now everything returns true for some reason
local script:
First_Name_Button.FocusLost:Connect(function()
if First_Name_Button.Text ~= nil then
local result = FilterTextEvent:InvokeServer(First_Name_Button.Text)
print(result)
end
end)
server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local FilterTextEvent = ReplicatedStorage.RemoteEvents.FilterText
function OnInvoke(player,text)
local filter
local success, errormsg = pcall(function()
filter = TextService:FilterStringAsync(text, player.UserId)
end)
if not success then
warn("Error filtering text:", text, ":", errormsg)
-- Put code here to handle filter failure
return false
else
return true
end
end
FilterTextEvent.OnServerInvoke = OnInvoke
EDIT There’s also another problem with your code. I’ve edited this post to include another solution.
Your rewritten code
First_Name_Button.FocusLost:Connect(function()
if First_Name_Button.Text ~= nil then
local success, filter = FilterTextEvent:InvokeServer(First_Name_Button.Text)
print(success, filter)
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local FilterTextEvent = ReplicatedStorage.RemoteEvents.FilterText
function OnInvoke(player,text)
local filter
local success, errormsg = pcall(function()
filter = (TextService:FilterStringAsync(text, player.UserId)):GetNonChatStringForUserAsync(player.UserId)
end)
if not success then
warn("Error filtering text:", text, ":", errormsg)
-- Put code here to handle filter failure
return false
else
return true, filter
end
end
FilterTextEvent.OnServerInvoke = OnInvoke
You’re returning only a bool that identifies whether or not the filter was successful, not the actual filtered text. If you want the function to return the filtered text, then return 2 parameters. For example, on the server:
if not success then
warn("Error filtering text:", text, ":", errormsg)
-- Put code here to handle filter failure
return false
else
return true, filter
end
Then, on the client:
First_Name_Button.FocusLost:Connect(function()
if First_Name_Button.Text ~= nil then
local success, result = FilterTextEvent:InvokeServer(First_Name_Button.Text)
print(success, result)
end
end)