How to filter a string?

local Repli = game:GetService("ReplicatedStorage")

Repli.BoothText.OnServerEvent:Connect(function(player, BoothText)
	local Boothnumber = player.hasBooth
	if Boothnumber.Value ~= 0 then
		local Booths = game.Workspace.Booths:GetChildren()
		for i, v in pairs(Booths)  do
			if v.Name == tostring(Boothnumber.Value) then
			v.TextPart.SurfaceGui.TextBox.Text = BoothText
			
		end
	end
end end)

I want to filter the BoothText with the Roblox filtering but I just can’t figure it out I’ve been trying for some time now. If you could help me you would make my day!

1 Like

heres a short answer for you !

replace the the PlayerFrom with the player and PlayerTo to the player the message is gonna be sent

game.Chat:FilterStringAsync(‘hi’,PlayerFrom,PlayerTo)

or

game.Chat:FilterStringForBroadcast(‘hi’,PlayerFrom) – used for Broadcasting

Read this page and you’ll be set for life when it comes to filtering strings!
TextService:FilterStringAsync (roblox.com)

but its not a message its a string that will be displayed on a sign

Ill read it thanks looks like the solution

1 Like

For that u should use this:
game.Chat:FilterStringForBroadcast(‘hi’,PlayerFrom)

it returns a filtered string

ahh so then “hi” would be the input message

Yes thats right.

i need the characters so i can reply.

but it doesnt work in studio does it work in a test server?

What error do u get when u run it?

local Repli = game:GetService("ReplicatedStorage")

Repli.BoothText.OnServerEvent:Connect(function(player, BoothText)
	local Boothnumber = player.hasBooth
	if Boothnumber.Value ~= 0 then
		local Booths = game.Workspace.Booths:GetChildren()
		for i, v in pairs(Booths)  do
			if v.Name == tostring(Boothnumber.Value) then
		
				local message = game.Chat:FilterStringForBroadcast(BoothText, player)
				v.TextPart.SurfaceGui.TextBox.Text = message
		end
	end
end end)

idk if thats the righ way but it doesnt filter text

You accidentally put the string before the player

from
local message = game.Chat:FilterStringForBroadcast(BoothText, player)
to
local message = game.Chat:FilterStringForBroadcast(player, BoothText)

then i get the error: Unable to cast value to Object

Place prints to debug

local Repli = game:GetService("ReplicatedStorage")

Repli.BoothText.OnServerEvent:Connect(function(player, BoothText)
	local Boothnumber = player:FindFirstChild("hasBooth")
	if not Boothnumber then
		warn("Boothnumber invalid")
		return
	end
	
	if Boothnumber.Value ~= 0 then
		print("Continue")
		local Booths = workspace.Booths:GetChildren()
		for i, v in pairs(Booths)  do
			print(Boothnumber.Value, v.Name == tostring(Boothnumber.Value))
			if v.Name == tostring(Boothnumber.Value) then
				local message = game:GetService("Chat"):FilterStringForBroadcast(BoothText, player)
				v.TextPart.SurfaceGui.TextBox.Text = message
			end
		end
	end
end)

If everything prints, you should be fine and it’s a studio thing.

2 Likes

it doesnt filter in studio do i need to publish the game or can i just play test it?

Maybe, try it with a multiaccount.

thank you saved me hours of failing

Perfect, however please make sure to wrap FilterStringAsync in a pcall, since it’s a network bound function, it might fail and break your script!
Always use pcall when the function name contains “Async”.

Yep, the filtering could be like this

local Chat = game:GetService("Chat")
local Success, message = pcall(Chat.FilterStringForBroadcast, Chat, BoothText, player)
if Success then
	v.TextPart.SurfaceGui.TextBox.Text = message
else
	warn(message)
end
1 Like