Whenever you create a new script, at the top of the script editor is the print function
print("Hello world!") It’s famous for being one of the first lines of code people learn how to write.
Print functions output text to the screen. Any time your phone sends you a notification, you’re seeing a print function in action!
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 lots of types of variables. String variables hold a mix of letters and numbers. They’re good for things like names or addresses, but not good for counting. String type variables always sit inside of quotation marks, “like this”.
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
"(Animal Name) are my favorite animal.".
To test your code, you’ll need to use the Output Window.
To open or close the Output window:
- Select the View menu tab.
- Click Output.
Test Your Script
The Output window displays print functions and helpful error messages for game developers whenever the game is run.
- Click Play to test your script. Your new string will show up in the Output window.
Returning to the Script
Now that you know how to test your script, let’s go back into the script editor.
- Stop the playtest.
- Go back to the script by clicking on the script editor.
Script Tab Missing?
If you don't see the script editor, double-click the name of the script in Explorer to reopen the script.
Teaching Tip - Make Sure Playtests are Stopped »
Make sure that students always click stop after testing a script. New users often forget to stop their game after testing.
Troubleshooting Your Code
No matter how long you’ve been coding, sometimes you’ll find errors that keep your program from running. 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, let’s 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.
- Click on the red message in the Output window; this will take you to where the error is found in your code.
These documents are licensed by Roblox Corporation under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Roblox, Powering Imagination, and Robux are trademarks of Roblox Corporation, registered in the United States and other countries.
Previous Create a Script Next Properties and BrickColor