Not filtering text string properly

Title says it all.

I know filtering doesn’t work in studio, and I tested this in a roblox game, but it will filter no matter what you input. I even tried copy and pasting the exact same string into the chat and it wasn’t filtered, but my script says it was.

LocalScript:

local sound = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Clans"):WaitForChild("Click")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("Clans"):WaitForChild("Create")

local namevalue = script.Parent.ClanName
local descriptionvalue = script.Parent.ClanDescription
local imagevalue = script.Parent.ClanImage

local textService = game:GetService("TextService")

local lightRed = Color3.fromRGB(255, 64, 67)
local lightGray = Color3.fromRGB(138, 138, 138)
local white = Color3.fromRGB(255, 255, 255)
local label = script.Parent.Parent.Error

local namestroke = script.Parent.Parent:WaitForChild("Name").TextBox.UIStroke
local descstroke = script.Parent.Parent:WaitForChild("Description").TextBox.UIStroke

local uiStroke = script.Parent.UIStroke
local button = script.Parent

local function checkValues()
	if namevalue.Value == "" or descriptionvalue.Value == "" or imagevalue.Value == 0 then
		return false
	end
	return true
end

local function updateButtonState()
	local valuesAreSet = checkValues()
	if valuesAreSet then
		button.Interactable = true
		button.TextColor3 = white
	else
		button.Interactable = false
		button.TextColor3 = lightGray
	end
end

local function filterTextAsync(player, text)
	local success, filteredText = pcall(function()
		return textService:FilterStringAsync(text, player.UserId):GetNonChatStringForBroadcastAsync()
	end)
	if success then
		return filteredText
	else
		return nil
	end
end

button.MouseButton1Click:Connect(function()
	sound:Play()
	if checkValues() then
		local filteredName = filterTextAsync(game.Players.LocalPlayer, namevalue.Value)
		local filteredDescription = filterTextAsync(game.Players.LocalPlayer, descriptionvalue.Value)

		local nameFiltered = filteredName ~= nil
		local descriptionFiltered = filteredDescription ~= nil

		namestroke.Color = nameFiltered and lightGray or lightRed
		descstroke.Color = descriptionFiltered and lightGray or lightRed

		if nameFiltered and descriptionFiltered then
			remote:FireServer(filteredName, filteredDescription, imagevalue.Value)
		else
			label.Visible = true
		end
	end
end)

game:GetService("RunService").RenderStepped:Connect(updateButtonState)

Thanks :mending_heart:

3 Likes

Still needing help on this. This is my first time working with filtering so I might be worse than usual.

Hello there!

I’m recreating the issue, but would you mind sharing the file as an .rbxl? It would be easier for me to edit it and tell you what exactly is wrong so I can guide you on how to fix it without me needing to recreate the gui’s and stuff.

-DiscMil

I cannot send the whole rbxl file as it would share a lot of unnecessary stuff.

I will send you a small demo version.

Give me a moment.

Yeah that’s perfect, only send me the stuff that the code requires, for example the RemoteEvents, the guis and that sound file doesn’t really matter as I can test code without needing that. I have some what established the issue already.

I removed pretty much all the unnecessary stuff, I left the firing of the remote event in there (but you don’t need where the remote event gets processed, that’s not necessary):

filteringtest.rbxm (17.0 KB)

Okay, sorry I was doing something. But is this what you mean no matter what you type it gets filtered?

yes, it will filter no matter what, even if you try it in an actual roblox game (because it shouldn’t filter even in studio, studio filters nothing)

Okay, yeah so is this what you’re trying to achive?

That’s weird… When I tried this in the roblox client it didn’t work.

Let me try it again.

EDIT: Misread your post, yes that is what I’m trying to achieve

I edited the code, plus added some there’s just a bug I need to fix cause even when I test it in Roblox Studio it does the same in the client now. Only in studio it let’s anything through.

1 Like

Let me know if this is what you’ve wanted to achieve so I can help you step by step on how to do this:

Yes, but I don’t want it to fire the remote event if it is filtered, I want it to not fire it and send the error to the player to change the title.

(basically, underneath the create button there is a textlabel that will say “Filtered, try again” and then will highlight the box that is filtered)

I don’t know what’s happening but it’s working and then it isn’t did you remove any image frames, values, labels or anything cause I keep need to comment and add or remove stuff from gui and code?

I removed an image, and you seem to have removed the description box:

image

No, it wasn’t deleted but for some reason the z-index was set to 1.

oh, no idea why that happened

can you send me the current script?

Yeah, I’ll breakdown the code and tell you want you need to do. Here’s an image of what I currently achieved. Tell me if this is good and i’ll proceed to write what you actually did wrong and what you need to do to solve this.

[image]

1 Like

Perfect, does it fire the remote event when it says “Text filtering failed!”?

Yeah, it does but you’ll be able to figure out what to do.

1 Like