Newline with \n issues

  1. What do you want to achieve? Textwrapping on certain letters, i dont want the holes so im trying to make my own textwrap system

  2. What is the issue? I need to find on which symbol do i have to fire the function to create a newline

  3. What solutions have you tried so far?

   local function replace_char3(pos, str, r)
   	return table.concat{str:sub(1,pos-1), r, str:sub(pos+1)}
   end
   
   local position = game:GetService("TextService"):GetTextSize(Text,script.Parent.MainFrame.DialogueText.TextSize,script.Parent.MainFrame.DialogueText.Font,Vector2.new(0.95,0.9))
   position += Vector2.new(1,1)
   
   Text = replace_char3(position.X,Text,"\n")
1 Like

Is the issue related to one of the characters not showing?

1 Like

https://gyazo.com/8feaacb869ebadc1a0fec08cb2a621f1 i changed this code

   Text = replace_char3(position.X,Text,"\n")

with this just so u can see better

   Text = replace_char3(40,Text,"\n")
1 Like

Why not just remove any unrecognised characters (so only keep stuff like standard whitespaces & alphanumeric characters)?

string.sub("text here", "[^%w%s]", "")
1 Like

Your script runs perfectly fine when I test it. Although the character in the index you pass(in our case 40) disappears. I’m asking you if the issue is related to this, or that for you a newline isn’t created at all.

thing is i need to somehow make it automatic, i want it to find in which string num i have to fire the function so it creates a new newline

1 Like

in this case i placed 40 so it would create a newline on num string len 40
in the case i want it to find that “40” and etc automatically

1 Like