Filterforbroadcast removes ctrl+J and new line

I have a name script which uses FilterForBroadcastasync, however, it removes any new lines/enters/ctrl + j which puts the text all into one line.
If anyone knows a simple alternative or workaround let me know please!

Maybe filter the lines individually and add the enters after?

Do you let users input the newlines, or is part of this text not actually generated by the user?

You only need to filter the part generated by the user if the latter is the case. So if “Survivor” and “No Faction” are generated by your game, these don’t have to go through the filter, so only filtering the first line is fine if that is the case.

(Just suggesting this as a workaround, not saying that this is not a bug)

The players write the names themselves in the chat, they type “name” ctrl +J “more stuff”.

1 Like

You could solve this in two ways, although other solutions probably exist:

  • Split the string based on newlines, filter all and merge them in the end (lots of requests though)
  • Filter the string, then split the original and filtered based on spaces:
  • “There was a \n censored word” --> "There","was","a","\n","censored","word"
  • “There was a \n ####### word” --> "There","was","a","########","word"
  • Go through original split string, whenever you see a newline, add at current position in new string
    (literally: for k,v in pairs(a) if v == "\n" then table.insert(b,k,v) end end
    Would definitely break if FilterForBroadcast also removes other things (like actual words) though
  • –> `“There”,“was”,“a”," \n","########",“word” --concat–> “There was a \n ######## word”

but they should fix FilterForBroadcast doing that, though

Can confirm this issue. It’s happening on my own game as well.

local Str = "hey\nhow\nare\nyou"
local BeforeFiltering = Str:gsub("\n", "[br]")
local AfterFiltering = FilterForBroadcast(BeforeFiltering):gsub("[br]","\n")
print(AfterFiltering) -- same as first print (provided it didnt sensor anything)

hacky but will work, convert new lines to “[br]” then back to new lines after filtering. you could change “[br]” to anything so people dont unintentionally create new lines.