How do I write multiple lines of code with Script.Source = "x"

I am making a plugin.
How do I write multiple lines of code in a script with the function

Script.Source = ""

I want to do something like

Script.Source = "print(Script.Parent.Name)
print(1)
print("String")"

but it shows an error.
Even doing it with an array shows an error.

How do I achieve this?

1 Like

Use a backslash ( \ ) to continue lines of code onto multiple lines.
Like this:

print("hello there \
	i am cool")
2 Likes

hm
Thanks it worked.
Is there a way to remove the extra spaces?
It doesn’t matter but it still bugs me :stuck_out_tongue:

Thank you

Square brackets also work.

print([[hello
goodbye]])
6 Likes

You can just backspace them, it won’t change anything.

print("hello there \
i am cool")

works the same as

print("hello there \
	i am cool")

I assume that’s what you meant. If I’m misinterpreting your question, let me know. :slight_smile:

1 Like

That might be because the string you’re setting as the source has indents.

1 Like

sourcewew
it doesnt have any spaces here

@Polyheximal
image
The script which is being loaded has some extra spaces

Edit: My bad I forgot to save the changes in plugin thats why the spaces were there.
Thank you for your help :slight_smile:

2 Likes

Blokav’s solutions would be way better here without worrying about escapes. Just saying

2 Likes

Additionally, \n can be used to create a new line.
Though, I endorse square brackets.

1 Like

Perhaps it does, but a little extra effort won’t hurt if it means that your script will look cleaner. That’s just my opinion anyways.

Just want to say that if you want to make extra ultra sure that there is no problems with putting in the code just do something like this

Script.Source = [====[
print("magic")
local function test()
    print([[yee]])
end
test()
]====]
1 Like