Heres the Code... this works...
local h = Instance.new("Message") h.Parent = Workspace h.Text = "Be sure to push the button then stand on the red brick " wait(5) h:Remove()
...this doesnt
local h = Instance.new("Message") h.Parent = Workspace h.Text = " be sure to push the button then stand on the red brick" wait(5) h:Remove()
help?
Problem
On line 3 of your second example, you create a single-line string
value. This means your string value only spans one line of code, before being cut off. If the string value isn't ended on the same line of code it started on, it will consider the string non-terminating
, thus breaking the script with a syntax error
.
Multi-line strings
What you're looking for is a multi-line string
value. This string can be created using 2 square braces ([[
), and ending with 2 square braces (]]
).
Here's a revised version of your code:
local h = Instance.new("Message") h.Parent = Workspace h.Text = [[be sure to push the button then stand on the red brick]] wait(5) h:Destroy() -- I also recommend using destroy
Or, if you wanted to have the actual text of [[
or ]]
in your string, you could start your string with a single bracket, and equal sign, and another single bracket (like this: [=[
).
Example:
print([=[ hello [[world]] ]=]) -- Don't forget to end it with the inverse symbol of what you started it with.
Escape characters
An alternative to the above example would be using an escape character
(the \
symbol). This symbol allows us the escape a string pattern, or avoid terminating one. We could use this symbol before what would terminate
our string, to "extend" it's length.
For example, let's say we wanted a quotation mark within a single-line string. We could say:
print("hello 'world'") -- prints: hello 'world'
or...
print('hello "world"') -- prints: hello "world"
or finally...
print("hello \"world\"") -- here we're using \" twice to tell the script not to terminate our string, but rather just add a quotation as a text. -- this will print: hello "world". without us having to use a different type of string.
Hope this helped!
I presume you are trying to create the text on multiple lines.
First of all, when the script runs, it will read the new line in your code as the end of a statement, and run the next line as a separate one, hence why your code doesn't work.
There is a simple way around this, and that's using \n
This is essentially just a backslash and an "n" which, when put into a string, will make a new line.
So you will want:
local h = Instance.new("Message") h.Parent = Workspace h.Text = " be sure to push the button\nthen stand on the red brick" wait(5) h:Remove()
However, I am pretty sure that Messages don't allow multiple lines of text, and you would be much better looking into using GUIs instead.