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.
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.
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)
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.
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)
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)