Need help with text filtering

  1. What do you want to achieve? Keep it simple and clear!
    I want to use a text box to allow the player to give themselves a custom name using a billboard gui attached to their head.
  2. What is the issue? Include screenshots / videos if possible!
    I can’t figure out how to filter the text then take the filtered text and apply it to the billboard gui.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I couldn’t find anything on the developer hub for filtering text from a text box to be used on a billboard gui.

My code consists of a local script which fires an event which the server side script receives and makes the changes to the billboard gui

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Activated:Connect(function()
	ReplicatedStorage.FilterRequest:FireServer(script.Parent.TextBox.Text)
end)

Server Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage.FilterRequest.OnServerEvent:Connect(function(player, txt)
	local Cloned = true
	if Cloned == true then
		ReplicatedStorage.NameGui:Clone().Parent = player.Character.Head
		player.Character.Head.NameGui.TextLabel.Text = txt
		Cloned = false
	else
		player.Character.Head.NameGui.TextLabel.Text = txt
	end
end)

Any help would be appreciated!

1 Like

You should read this article on text filtering: TextService | Documentation - Roblox Creator Hub

From there, the function will return the filtered string which you can simply set to be the Text attribute of the Gui objects underneath the BillboardGui object.

Hope this helps,
-Tom :slight_smile:

I’ve already looked at that article, but I still don’t understand how to write the code that will filter the text.

If you want to filter text, I’d use :FilterStringForBroadcast() from ChatService. Since you’re using textbox, the code would look something like this:

-- in the TextBox as a localscript
local textbox = script.Parent
textbox.FocusLost:Connect(function(enterPressed)
	if not enterPressed then
		return
	else
		game:GetService("ReplicatedStorage").Filter:FireServer(textbox.Text) -- make sure "Filter" is a RemoteEvent and is a child of ReplicatedStorage
	end
end)
-- in ServerScriptService (filterstringforbroadcast is deprecated for localscripts)
game:GetService("ReplicatedStorage").Filter.OnServerEvent:Connect(function(plr, txt)
	local filteredString = game:GetService("Chat"):FilterStringForBroadcast(txt, plr)
    -- do your billboard code here
	print(filteredString) -- please acknowledge that it'll filter ingame, not in studio
end)
2 Likes

Thanks @Doqee I just tested it out in a private game I published and filtering works!

1 Like

Of course! If you’re wanting to make your filter less restrictive (for instance, if a user is 13+ then more strings will be shown to them rather than an underaged account), have a look at :FilterStringAsync().

Edit: since I seen you struggling with understanding the function, take a look at the code beneath, it works the same way as I stated beforehand:

game:GetService("ReplicatedStorage").Filter.OnServerEvent:Connect(function(plr, txt)
	for _, i in ipairs(game.Players:GetPlayers()) do
		local filteredString = game:GetService("Chat"):FilterStringAsync(txt, plr, i)
		print("this is a less restrictive string: "..filteredString)
	end
end)

Comparison between 2:
image