Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add Filter on Textbox or Textlabel?

Trying to filter the textbox response from the GUI. This is here making a label, what label? Basically what this does is make a block and a Billboard GUI to label things. On line 62, I tried to add a filter but to no avail as users can place swear words.

SERVERSCRIPT

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Label1 = Instance.new("RemoteEvent", ReplicatedStorage)
Label1.Name = "LabelGUI"


--Code runs

local function Establishment(player, Text)
	local char = player.Character
	
	--Setup name. Creation
	local mod = Instance.new("Model")
	local part = Instance.new("Part", game.workspace)
	local GUI = Instance.new("BillboardGui", part)
	local GUIText = Instance.new("TextLabel", GUI)
	
	--Set BRICK PROPERTY
	part.Size = Vector3.new(0.5,0.2,0.5)
	part.CanCollide = true
	part.Transparency = 0
	part.Name = "Head"
	part.Locked = false
	part.Anchored = true
	part.BrickColor = BrickColor.new("Gold")
	part.Material = Enum.Material.Neon
	part.Archivable = true
	part.CastShadow = false
	part.Name = "Label"
	
	--Location/Spawn set
	mod.PrimaryPart = part
	mod.Parent = char
	mod:SetPrimaryPartCFrame(char.Head.CFrame+Vector3.new(0,1,-1.5))
	mod:Destroy()
	part.Rotation = Vector3.new(0,0,0) --Make sure that it does not look like a mess.
	
	
	--Properties to the GUI
	GUI.Enabled = true
	GUI.ExtentsOffset = Vector3.new(0,4,0)
	GUI.MaxDistance = 35
	GUI.Name = player.name
	GUI.Parent = part
	GUI.Size = UDim2.new(0 ,200 ,0 ,50)
	wait()
	GUI.Adornee = part
	
	--Properties to the text
	GUIText.BackgroundTransparency = 1
	GUIText.BorderSizePixel = 0
	GUIText.Visible = true
	GUIText.Font = Enum.Font.SourceSansLight
	GUIText.RichText = true
	GUIText.TextColor3 = Color3.new(255,255,255)
	GUIText.TextSize = 14
	GUIText.TextScaled = true
	GUIText.TextStrokeTransparency = 0
	GUIText.Parent = GUI
	GUIText.Size = UDim2.new(0 ,200 ,0 ,50)
	
	--Set it to Name thing
	GUIText.Text = Text
	
end
Label1.OnServerEvent:Connect(Establishment)

LOCAL SCRIPT

local Insert = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Label1 = ReplicatedStorage:WaitForChild("LabelGUI")

Insert.MouseButton1Click:Connect(function()
	--Light the transmitters
	Label1:FireServer(script.Parent.Parent.TextBox.Text)
	
	--Wait to reload to not spam out.
	script.Parent.Visible = false
	script.Parent.Parent.Reloading.Visible = true
	wait(10)
	script.Parent.Visible = true
	script.Parent.Parent.Reloading.Visible = false
end)

2 answers

✓ Accepted answer

We'll you have a pretty good question so let me explain this,

We will use TextService for it's FilterStringAsync!

We create a Variable for TextService and a filteredMessage variable, then we create a pcall function just incase something happens, we set the filteredMessage to a filteredVersion of the text by setting in the parameters the text and their userid, then we set the filteredText and check if it's allowed through the filter or not!

(by the way TextService only works on ServerScripts)

local TextService = game:GetService("TextService")

local filteredMessage = ""

pcall(function()

	filteredMessage = TextService:FilterStringAsync(tostring(Text), player.UserId)
	filteredMessage = filteredMessage:GetNonChatStringForBroadcastAsync()

end)

Sorry for the confusion, you had to do GetNonChatStringForBroadcastAsync that's my mistake, Here's the code working with your script

local ReplicatedStorage = game:GetService("ReplicatedStorage") local Label1 = Instance.new("RemoteEvent", ReplicatedStorage) Label1.Name = "LabelGUI"

--Code runs

local function Establishment(player, Text) local char = player.Character

--Setup name. Creation
local mod = Instance.new("Model")
local part = Instance.new("Part", game.workspace)
local GUI = Instance.new("BillboardGui", part)
local GUIText = Instance.new("TextLabel", GUI)

--Set BRICK PROPERTY
part.Size = Vector3.new(0.5,0.2,0.5)
part.CanCollide = true
part.Transparency = 0
part.Name = "Head"
part.Locked = false
part.Anchored = true
part.BrickColor = BrickColor.new("Gold")
part.Material = Enum.Material.Neon
part.Archivable = true
part.CastShadow = false
part.Name = "Label"

--Location/Spawn set
mod.PrimaryPart = part
mod.Parent = char
mod:SetPrimaryPartCFrame(char.Head.CFrame+Vector3.new(0,1,-1.5))
mod:Destroy()
part.Rotation = Vector3.new(0,0,0) --Make sure that it does not look like a mess.


--Properties to the GUI
GUI.Enabled = true
GUI.ExtentsOffset = Vector3.new(0,4,0)
GUI.MaxDistance = 35
GUI.Name = player.name
GUI.Parent = part
GUI.Size = UDim2.new(0 ,200 ,0 ,50)
wait()
GUI.Adornee = part

--Properties to the text
GUIText.BackgroundTransparency = 1
GUIText.BorderSizePixel = 0
GUIText.Visible = true
GUIText.Font = Enum.Font.SourceSansLight
GUIText.RichText = true
GUIText.TextColor3 = Color3.new(255,255,255)
GUIText.TextSize = 14
GUIText.TextScaled = true
GUIText.TextStrokeTransparency = 0
GUIText.Parent = GUI
GUIText.Size = UDim2.new(0 ,200 ,0 ,50)

--Set it to Name thing

local TextService = game:GetService("TextService")

local filteredMessage = ""

pcall(function()

filteredMessage = TextService:FilterStringAsync(tostring(Text), player.UserId)
filteredMessage = filteredMessage:GetNonChatStringForBroadcastAsync()

end)

GUIText.Text = filteredMessage

end Label1.OnServerEvent:Connect(Establishment)

2 comments

0

I found an error that says. Unable to assign property Text. string expected, got Instance. when using GUIText.Text = filteredMessage

0

Don't know where to add in the server script though!

MattVSNNL, I don't know where to implement your code in. As I tried. It ended up giving me errors and failing.

1 comment

0

Let me edit it for you

This discussion is preserved as it was. New answers, comments, and votes are closed.