So I am making a name save for a player’s pet in my game, it would go through a local script and be sent to the server to manage and return whether its properly filtered or not, how would I be able to check this is working?
This is the code I currently have for it and im not sure if it works or how to even test it without getting myself banned.
local TextService = game:GetService(“TextService”)
local system = game.ReplicatedStorage.System
local filter = system.Filter
local gui = script.FilterNotification
filter.OnServerEvent:Connect(function(player,message)
print(message…player.UserId)
local success, errorMessage = pcall(function()
local filteredTextResult = TextService:FilterStringAsync(message, player.UserId)
print(filteredTextResult)
end)
if success then
print(“Name accepted”)
local gui = player.PlayerGui:WaitForChild(“NamePet”)
gui:Destroy()
local val = player.PetName
print(message)
val.Value = message
end
if not success then
warn(“Error filtering text:”, message, “:”, errorMessage)
print(“FILTERED”)
local messageFail = gui:Clone()
messageFail.Parent = player.PlayerGui.NamePet
end
end)
1 Like
You are not using it correctly, you check whether or not the filter errors, and if it doesn’t you set the name to an unfiltered version rather than the filtered version. You should set the name to filteredTextResult:GetNonChatStringForBroadcastAsync()
which will receive the filtered version appropriate for every player in the game.
As for checking whether or not that message was filtered at all, you could remove all ‘#’ in the string, filter it and then check whether or not the string contains ‘#’ (which means it was filtered.)
Also, you should use code tags (```lua) to display code.
Thank you, sorry im new to the forums. Ill test that out now
Just so you are aware, Filtering doesn’t work in studio so you should not test in studio.
I also just made a function to keep trying to filter should the filter fail for any reason (since filters can fail, since they make an http request)
You’re free to use it or make your own.
local function filterText(Player, String)
local textObject;
repeat wait(.1)
pcall(function()
textObject = game:GetService'TextService':FilterStringAsync(String, Player.UserId);
end)
until textObject;
local filteredString;
repeat wait(.1)
pcall(function()
filteredString = textObject:GetNonChatStringForBroadcastAsync();
end)
until filteredString;
return filteredString;
end
This function can infinitely yield if the roblox filter is down.
6 Likes
I actually got it working! Thank you so much though wouldnt of figured it out without your help. I added what you said with the filteredTextResult and implemented
for i = 1,length do
local check = string.sub(name,i,i)
print(check)
if check == "#" then
print("Filtered")
warn("Error filtering text:", message, ":", errorMessage)
filtered = true
print("FILTERED")
local messageFail = gui:Clone()
messageFail.Parent = player.PlayerGui
break
end
filtered = false
end
if filtered == false then
1 Like