Text Filter Help Needed

Good day all, i want to know how can i use textfiltering, because now I have a UI where players can type something and it will appear on a part, but your can say anything, so I want to use the defualt roblox textfilter to filter the text first before showing it

Here are my 2 sections where I would like to integrate it in.

Boothtitle.OnServerEvent:Connect(function(player, text)
	for _, booth in pairs(boothFolder:GetChildren()) do
		if booth:IsA("Model") then
			local ownerSign = booth:FindFirstChild("OwnerSign")
			if ownerSign and ownerSign:GetAttribute("Owner") == player.UserId then
				local boothUISFolder = booth:FindFirstChild("SurfaceUis")
				if boothUISFolder then
					local boothTitleGui = boothUISFolder:FindFirstChild("BoothTitle")
					if boothTitleGui then
						local surfaceGui = boothTitleGui:FindFirstChildWhichIsA("SurfaceGui")
						if surfaceGui then
							local titleLabel = surfaceGui:FindFirstChild("TITLE")
							if titleLabel then
								titleLabel.Text = tostring(text)
								surfaceGui.Enabled = true
							end
						end
					end
				end
				break
			end
		end
	end
end)

BoothDescription.OnServerEvent:Connect(function(player, Text)
	for _, booth in boothFolder:GetChildren() do
		local OwnerSign = booth:FindFirstChild("OwnerSign")
		if OwnerSign and OwnerSign:GetAttribute("Owner") == player.UserId then

			local SurfaceGUI = booth:FindFirstChild("SurfaceUis")
			if SurfaceGUI then
				local BoothDescriptionPart = SurfaceGUI:FindFirstChild("BoothDescription")
				if BoothDescriptionPart then
					local TestGUI = BoothDescriptionPart:FindFirstChildWhichIsA("SurfaceGui")
					if TestGUI then
						
						local TestDescription = TestGUI:FindFirstChildWhichIsA("TextLabel")
						TestDescription.Text = tostring(Text)
						
					else
					end
				end
			end
		end
	end
end)

Little trick that will prevent your code from going into orbit horizontally (and generally makes it easier to read) is this

Boothtitle.OnServerEvent:Connect(function(player, text)
	for _, booth in pairs(boothFolder:GetChildren()) do

		if not booth:IsA("Model") then continue end

		local ownerSign = booth:FindFirstChild("OwnerSign")
		if not ownerSign or ownerSign:GetAttribyte("Owner") ~= player.UserId then continue end

		local boothUISFolder = booth:FindFirstChild("SurfaceUis")
		if not boothUISFolder then return end

		local boothTitleGui = boothUISFolder:FindFirstChild("BoothTitle")
		if not boothTitleGui then return end

		local surfaceGui = boothTitleGui:FindFirstChildWhichIsA("SurfaceGui")
		if not surfaceGui then return end

		local titleLabel = surfaceGui:FindFirstChild("TITLE")
		if not titleLabel then break end

		titleLabel.Text = tostring(text)
		surfaceGui.Enabled = true
	end
end)

The returns act as a break


As for your question, it’s done through TextService, for non chat filtering:

titleLabel.Text = TextService:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync()
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.