How can I put a string on multiple lines?

I want to be able to put string on a separate line of code. Here is how one would do in manually

local z = [[
line1
line2
etc
]]

But I want to be able to do this automatically. Now introducing one line of code that isnt all that important!

local finished = ""
for _, detail in pairs(details.Services)  do
	if detail.Use then
		code = tostring(code)..tostring(detail.Code)
	end
end

What does this code do?

Simple, it screams it loops through a table then takes a code value inside said table and puts it into the finished value.

Ps what the table looks like:

			local details = {
				Services = {
					TeamService = {
						Use = true,
						Code = "local teamService = game:GetService('TeamService')"
					},
					ServerStorage = {
						Use = true,
						Code = "local teamService = game:GetService('ServerStorage')"
					},
				}
			}

Anyhow upon doing this code and changing the text of a taxtlabel to this can see wellll this:

local teamService = game:GetService(ā€˜ServerStorageā€™)local teamService = game:GetService(ā€˜TeamServiceā€™)

all on one single line. But what if I want it to look like this:

local teamService = game:GetService(ā€˜ServerStorageā€™)
local teamService = game:GetService(ā€˜TeamServiceā€™)

Much more clean lets be honest. So how can I do this? cause I must learn!

Use \n.

code = code .. '\n' .. detail.Code
2 Likes

Now im just getting:

/nlocal teamService = game:GetService(ā€˜ServerStorageā€™)/nlocal teamService = game:GetService(ā€˜TeamServiceā€™)

New code:

			for _, detail in pairs(details.Services)  do
				if detail.Use then
					code = code .. '/n' .. detail.Code
				end
			end

Wrong slash, it has to be a backslash

2 Likes

Btw, I donā€™t know why I didnā€™t add this in my original reply but you can also use \ to escape the newline if you prefer a more visually accurate look- should give you the same result but might look funny at first

code = code .. '\
' .. detail.Code
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.