Welcome back. In the last lesson, you created PracticeScript, used print(), started a playtest with Play, and checked Output to prove the Script ran.
Now you will make that Script easier for a human to understand. You will add single-line comments: notes written inside your code that Roblox ignores when the game runs. This is a small skill, but it becomes increasingly useful as your scripts grow beyond a few lines.
Comments are notes, not instructions
A Script contains two kinds of text:
- Code, which Roblox reads and runs.
- Comments, which are notes for people reading the Script.
In Luau, a single-line comment begins with two hyphens:
-- This is a comment
The two hyphens tell Luau: “Ignore the rest of this line.” The comment will not appear in Output, change the game, or cause an instruction to run.
For example:
-- Show a message in the Output window
print("PracticeScript is running")
When you playtest this Script, Output shows only:
PracticeScript is running
The first line helps you understand the second line, but Roblox does not execute it.
Roblox Scripting Basics | Printing, Variables & Comments
Watch “Roblox Scripting Basics | Printing, Variables & Comments” by CovertCode for a short visual explanation of why comments exist and how two hyphens change a line from code into a note.
Watch the purpose to see why comments help people understand scripts. Then watch the syntax demo, focusing on the two hyphens and the fact that everything after them on that line is ignored.
The single-line comment rule
A comment starts at -- and continues only until you press Enter. The next line is not automatically part of that comment.
-- This is a comment.
This is not a comment.
The second line would cause a problem because it is plain English, not valid Luau code. If your note needs two lines, start each line with two hyphens:
-- This Script prints two messages.
-- We use them to verify that Output is working.
print("First message")
print("Second message")
Use the readable style of placing one space after the hyphens:
-- Good comment style
Technically, --Good comment style also works, but the space makes your code easier to scan.
Luau comments | Documentation - Roblox Creator Hub
Read the official Roblox Creator Hub page “Luau comments” to confirm the exact single-line comment rule in Studio.
In the “Single-line comments” section, read the single-line explanation. Then continue through the keyboard-shortcut sentence and the example immediately below it. Focus on these details: comments can appear outside strings, they end at the end of a line, and a longer note needs -- on each new line.
Add comments to PracticeScript
Open PracticeScript in ServerScriptService. Keep your existing print() lines, but add comments that describe what the Script is doing.
Try this complete version:
-- This Script checks that server-side code is running.
print("PracticeScript started successfully")
-- This message confirms that Output can show more than one line.
print("I can see this in Output")
Now test it:
- Open Output if it is not already visible.
- Click Play.
- Look for the two messages.
- Click Stop.
Only the print() messages should appear in Output. The comment text should not appear.
That is the key test for a comment: it stays visible in the Script editor for you, but it has no effect on what runs.
Comments can also go after code
A comment does not have to occupy its own line. You can write it after an instruction:
print("PracticeScript started successfully") -- Confirm the Script began running
Luau runs the print() instruction, then ignores everything beginning at --.
For a beginner script, comments on their own line are often easier to read:
-- Confirm the Script began running
print("PracticeScript started successfully")
Both forms are valid. Use the form that makes the Script clearest.
One important exception: hyphens inside quotation marks are text, not a comment.
print("Type -- before a comment")
Here, Output displays:
Type -- before a comment
Luau sees the hyphens as part of the message because they are inside the string’s quotation marks.
Write comments that explain a purpose
A comment is most useful when it explains something that the code alone does not make obvious.
Compare these two comments:
-- Print a message
print("PracticeScript started successfully")
-- Confirm that the server Script starts when the playtest begins.
print("PracticeScript started successfully")
The first comment merely repeats what the code visibly does. The second says why the message exists: it is a test that the server Script started.
As your projects gain more scripts, aim for comments that answer one of these questions:
- What is this Script responsible for?
- Why is this line or group of lines needed?
- What should a future reader check or change here?
For your current Script, revise the first comment in your own words. For example:
-- Startup check for my first Roblox server Script.
print("PracticeScript started successfully")
The exact wording is up to you. The useful part is that someone opening the Script can immediately understand its purpose.
A careful testing use
Comments can also temporarily prevent a line of code from running:
-- print("Temporary test message")
print("This message still runs")
During a playtest, only the second message appears. The first line is still stored in your Script, but Roblox ignores it because it begins with --.
This can be useful while testing, but use it carefully. A comment should not become a permanent way to hide confusing or broken code. For now, its main role is simple: make your Script understandable.
If something goes wrong
Use this quick check:
- A comment needs two hyphens:
--. - One hyphen,
-, is not a comment. - Put comment text after the two hyphens.
- Add
--again on every new comment line. - Do not expect a comment to appear in Output.
- Do not put a comment note inside quotation marks unless you want it printed as text.
Key takeaways
A single-line comment starts with --, and Luau ignores everything after it until the line ends.
You used comments to explain what PracticeScript is checking, without changing what the Script prints to Output. Clear comments describe a Script’s purpose or explain why code is present; they do not need to narrate every obvious line.
Next, you will begin storing information in your scripts with local variables—names that hold values such as numbers, text, true/false values, and nil.
Can't find a good explanation? Sign up and we'll make it for you
Sign up