Your First Script
Roblox uses a programming language called Luau. Let's write your first script and learn the syntax.
Creating a Script
In the Explorer window, hover over ServerScriptService and click the + icon. Select Script. This creates a new Server Script. Double-click it to open the code editor.
The Print Function
By default, the script contains print("Hello world!"). The print() function sends a message to the Output window. This is your most powerful tool for debugging.
print("The script has started running!")
Variables
Variables store data so you can use it later. In modern Luau, you should always declare variables using the local keyword. This ensures the variable is only accessible within the current scope, saving memory and preventing bugs.
local playerName = "ekian" -- String (text)
local playerHealth = 100 -- Number
local isAlive = true -- Boolean (true/false)
print(playerName .. " has " .. playerHealth .. " health.")
Modifying Properties with Code
You can change the properties of Parts via code. First, you must find the Part in the Explorer using dots (.).
-- Find the part named "Baseplate" inside Workspace
local baseplate = workspace.Baseplate
-- Modern wait function (Never use wait() without task.)
task.wait(3)
-- Change its color and make it invisible
baseplate.BrickColor = BrickColor.new("Really red")
baseplate.Transparency = 0.5