Hastag filter to a textbox

Hello! So I have this script where a player needs to type in a textbox for other players to see. How would I add a roblox hastag filter to it? I checked youtube and there is none tutorials for textboxs.

What do you mean? Scripting is about combining different elements. You filter a textbox the same way you filter a chat message or anything else. You take a string, use the filter function on it, and then do something with the string.

am new to adding hastag fitlers. thats why I came to ask devforum.

Here’s a tutorial on the Creator Documentation Website:

Text Filtering | Roblox Creator Documentation

local TextBox = script.Parent

local function onKeyPress(inputObject, gameProcessedEvent)
if gameProcessedEvent then
return
end

local textBoxText = TextBox.Text
local text = inputObject.Text
local newText = textBoxText..text

TextBox.Text = newText

end

TextBox.FocusLost:connect(function(enterPressed)
if enterPressed then
local textBoxText = TextBox.Text
local newText = textBoxText…"
"

    TextBox.Text = newText
end

end)

TextBox.Focused:connect(function()
local textBoxText = TextBox.Text
local newText = textBoxText…"|"

TextBox.Text = newText

end)

game:GetService(“UserInputService”).TextBoxFocusReleased:connect(function(inputObject)
onKeyPress(inputObject, false)
end)

game:GetService(“UserInputService”).TextBoxKeyPressed:connect(function(inputObject)
onKeyPress(inputObject, false)
end)

game:GetService(“UserInputService”).TextBoxFocusChanged:connect(function(inputObject)
onKeyPress(inputObject, false)
end)

This is not possible using the TextBox object.
You will have to create your own custom object to do this.

It is 100% possible using a textBox object, I’ll share how in just a second.

What you need to do is have a local script parented to the textbox, a RemoteFunction in ReplicatedStorage, and a Script in ServerScriptService

In the localscript it should look like this:

local player = game:GetService("Players").LocalPlayer

-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local Filter = game:GetService('ReplicatedStorage').Filter

local function onFocusLost(enterPressed, inputObject)
	if enterPressed then -- Anything in here runs when the player presses enter in the textbox
		local message = textBox.Text --Get the user-inputed text
		local filteredMessage = Filter:InvokeServer(message) -- filter it using the remote function
		textBox.Text = filteredMessage -- set the text to the filtered message
	end
end

textBox.FocusLost:Connect(onFocusLost) -- Connect to the function

Solution based of of the solution to this post: How do you filter text? - #8 by Dummiez
Small changes made in regards to using a remote function since roblox doesn’t like filtering from a local script

NOTE: FILTERING DOESN’T WORK IN STUDIOS, TEST IN ROBLOX