This is hella confusing to read. Are you talking about ..?
local RandomString = "hi,"
local extraString = "I have achieved godhood"
print(RandomString.. extraString) -- This is one way you could do this.
print(RandomString, extraString) -- Second way you could do this.
local stringToAdd = {Line1 = "Hi", Line2 = "She likes whatever she likes bc I don't know!")
local ex = {Name = "FroDev", Title = "Pro Scripter", Desc = "She is a girl guys", Cheese = "idk what to put here"}
print(ex.Name, ex.Desc, stringToAdd.Line2, ex.Cheese)
This is a very niche functionality that it’s likely better to opt for string patterns or arrays instead. Regardless, here is a solution I came up with.
Creating new lines with the Return/Enter key is kind of weird, a problem I solved in this workaround:
Applying that workaround, I split the message by new lines, inserted a new string at a line number, and turned it back into a string. Here is an example you can run in the console:
--!strict
local message = [[Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Curabitur at dignissim magna, et gravida nisi.
Ut nec ornare dolor. Nam dolor nisi, venenatis sit amet porta eu, egestas eu orci.
Phasellus faucibus fermentum nibh a tempus.
Pellentesque quis porttitor nulla.
Morbi malesuada quam quis dolor lacinia luctus.
Quisque pulvinar imperdiet arcu ac egestas. Ut quis aliquet massa.
Nullam sed leo tortor.
Praesent ultricies vestibulum nisl, ut interdum justo mollis non.
In semper justo eu imperdiet vehicula.
Quisque porta, nibh quis lobortis feugiat, libero lectus porta nibh, in fermentum felis arcu sit amet metus.
Aliquam pharetra lorem vitae vulputate pretium. Sed congue rhoncus metus sit amet efficitur.
Quisque in varius magna, at sollicitudin justo. Quisque mollis sagittis scelerisque.
Integer tempus vehicula justo. Aenean malesuada maximus nibh feugiat tristique.
Donec sed iaculis mauris. Suspendisse sodales nibh non mi pharetra varius.]]
-- parses newlines created by the Enter/Return key into "\n"
local function parse_newlines(str: string): string
return string.gsub(str, "\n", "\\n")
end
-- splits string by "\n"
local function split_newlines(str: string): {string}
return string.split(parse_newlines(str), "\\n")
end
-- inserts string into another string with newlines with optional padding
local function insertStringAtLine(original: string, add: string, at: number, upPadding: boolean?, downPadding: boolean?): string
local lines: {string} = split_newlines(original)
at = math.clamp(at, 1, #lines)
if upPadding == true then
table.insert(lines, at, "")
at += 1
end
table.insert(lines, at, add)
if downPadding == true then
at += 1
table.insert(lines, at, "")
end
local newString: string = ""
for _: number, line: string in lines do
if newString ~= "" then
newString ..= "\n"
end
if line ~= "" then
newString ..= line
end
end
return newString
end
local message = insertStringAtLine(message, "Hello, World!", 9, true, false)
-- this will print properly in the console
print(message)
-- this will translate nicely into text objects
local screenGui = Instance.new("ScreenGui", game:GetService("StarterGui"))
local textBox = Instance.new("TextBox", screenGui)
textBox.Text = message
textBox.ClearTextOnFocus = false
textBox.Size = UDim2.fromScale(0.5, 1)