How-to: Roblox Scripting Basics

This guide introduces you to scripting in Roblox Studio. You’ll learn what scripting is, how to use simple commands like print, and how to start modifying properties of objects in your game. By the end, you’ll also understand variables and functions, which are essential tools for writing more powerful code.


1. What is Scripting?

Scripting (or coding) is just giving a computer instructions to follow, step by step. In Roblox Studio, scripting allows you to:

  • Change properties of parts in your game
  • Add interactivity
  • Make features like moving platforms, obstacles, or checkpoints

We’ll be using Lua, Roblox’s scripting language.


2. Setting Up Roblox Studio

  1. Open Roblox Studio.
  2. Start with a simple template — for this lesson, a Baseplate works best.
  3. Open the following panels (if they aren’t already):
    • Explorer
    • Properties
    • Output

These panels will help you see your game’s structure, details of objects, and any messages from your code.


3. Creating Your First Script

  1. In Explorer, right-click ServerScriptService.
  2. Choose Insert Object > Script.
  3. Delete the default code.

Now you can type your own instructions!


4. Using print

The simplest command is print(). It outputs a message to the Output window.

Example:

print("Hello world")
print(5)

When you click Play Solo, the output will show:

Hello world
5

This shows how the script runs each line in order.


5. Referring to Objects in the Game

Scripts can access anything you see in the Explorer. For example, the Baseplate has a property called BrickColor.

You can print its color like this:

print(game.Workspace.Baseplate.BrickColor)

If you change the Baseplate’s color in Properties, the script will show the new color when you run it.


6. Changing Properties with Code

Instead of just printing, you can assign values to properties.

Example: make the Baseplate partly see-through:

game.Workspace.Baseplate.Transparency = 0.5

Now when you run the game, the Baseplate becomes semi-transparent. You can change any property this way—color, size, collision, and more.


7. Using Variables

Typing game.Workspace.Baseplate every time gets tiring. Instead, use a variable:

local myBaseplate = game.Workspace.Baseplate
myBaseplate.CanCollide = false

Now the player will fall through the Baseplate because collisions are disabled.

You can also use variables to store numbers, text, or other values:

local score = 0

8. Writing Functions

A function is a reusable block of code. Instead of typing the same lines over and over, you put them in a function and “call” it whenever you want.

Example:

local myBaseplate = game.Workspace.Baseplate

local function makeBaseplateRed()
    myBaseplate.CanCollide = false
    myBaseplate.BrickColor = BrickColor.Red()
end

makeBaseplateRed()

Here, the Baseplate turns red and becomes non-collidable.


9. Function Parameters

Functions can also take parameters (inputs), so you can change what they do without rewriting code.

Example:

local function changeColor(message, color)
    print(message)
    game.Workspace.Baseplate.BrickColor = color
end

changeColor("I’m red now!", BrickColor.Red())
changeColor("Now I’m green!", BrickColor.Green())

The function works differently depending on the values you give it.


10. Summary of What You Learned

  • Scripts live in objects like ServerScriptService.
  • print() shows information in the Output panel.
  • You can access objects with game.Workspace.ObjectName.Property.
  • You can change properties with =.
  • Variables save values or objects for reuse.
  • Functions let you group code and reuse it.
  • Parameters make functions flexible.

This is just the beginning. In future lessons, you’ll use these basics to build actual game mechanics—like platforms, obstacles, and interactive features.