Whenever you create a new script, at the top of the script editor, is the print function. Print functions display text to the screen. It’s one of the first functions many people learn since it’s a simple way of giving the script a command.
Below is an example of the print function typed out and it’s output, what you’ll see once the script runs.
Variable Types - Strings
"Hello World" is a string variable type. Variables are containers for information the program can use and change, like player names or points.
There are many variable types. String variables hold a mix of letters and numbers. They’re used to store information like names. String type variables always sit inside of quotation marks,
Examples of strings:
"You just joined the game!"
"There are 50 players left"
Code Your Own Message
Instead of saying
Hello World, create your own message by changing the string in the print function.
- In the Explorer, hover over ServerScriptService. Click the
and select Script.
- In the Script Editor, replace
"Hello World"with a string that includes your favorite animal.
To test your code, use the Output Window. This window shows print output and errors from scripts.
To open the Output Window and test your script:
- Select the View menu tab.
- Click Output. The window will appear at the bottom of Roblox Studio.
- To test the script, press Play. Your new string will show up in the Output window.
- Since you’ve tested the script, Stop the playtest. You can now return to the Script tab to make any more changes or test out other strings.
Script Tab Missing? »
If you don’t see the script editor, double-click the name of the script in Explorer to reopen the script.
Troubleshooting Your Code
No matter how long you’ve been coding, sometimes things won’t run on the first try. Troubleshooting is the process of looking through your code to find and fix problems.
If your code didn’t work:
- Make sure
- The string is surrounded by quotation marks:
- The string is inside the parentheses:
- Ask a friend for help or try re-doing your work from the start.
Create an Error
To better understand what errors look like, purposely create an error.
- Open the script.
- Delete a quotation mark from the print statement.
- Hover over the red line to see an error message. In this case, you should see
Unfinished stringmeaning the string is missing a quotation mark.
Read an Error
Error messages show up as red lines in both the Script Editor and Output Window. You can use these error messages to help pinpoint the problem.
- Press Play to run your code.
- Notice the red error in the Output Window. Each error has a unique way of describing it. In this case, a “malformed string” means that string is missing something.
- Click on the red message in the Output window; this will take you to where the error is found in your code.