Introduction to Scripting on Roblox Studio

Jul 21, 2024

Introduction to Scripting on Roblox Studio

Opening Statement

  • Scenario: You're opening up Roblox Studio with a great game idea but realize you don't know how to make the game work.
  • Common Issue: Beginners often feel confused by scripting jargon on Roblox.
  • Objective: This guide aims to simplify scripting for beginners using Roblox Studio.

Initial Setup

  1. Open Roblox Studio: Start a new project with a base plate.
  2. Create a Part: Place and customize a part; for example, make it pink.
  3. Naming: Name the part (e.g., "pink part").

Building Your Script

  1. Insert a Script: Right-click the part and insert a new script.
  2. Define Variables:
    • local part = script.Parent
    • Variables store values (e.g., instances, strings, numbers).
    • Ensure to follow proper case sensitivity.
  3. Creating a Part with Script:
    • local part = Instance.new('Part')
    • Set parent property: part.Parent = game.Workspace
  4. Change Properties:
    • Example: part.Transparency = 0.5
    • Use auto-fill for efficiency.
  5. Running Your Code: Test the script by playing the game.

Boolean Values

  1. Definition: Boolean values are true/false values, e.g., checkboxes in Studio.
  2. Example: part.CastShadow = false.
  3. Wait Command:
    • Use task.wait() for better performance.
    • Numbers do not have quotation marks; strings do.

Printing and Debugging

  1. Print Statements: Useful for debugging.
  2. Example: print('Hi') or print(5), combined: print('Hi ' .. 5).
  3. Math Operations: Printable (e.g., print(3 + 3) results in 6).

Introduction to Functions

  1. Definition: Functions perform specific actions.
  2. Syntax:
    • Example:
      function add10(x)
          local y = x + 10
          print(y)
          return y
      end
      
  3. Local vs Global: Local functions/variables only accessible in their scope.
  4. Calling Functions: add10(2).

If Statements

  1. Definition: Checks conditions and runs code if true.
  2. Example:
    local part = script.Parent
    if part.Anchored == true then
        part.Color = Color3.fromRGB(255, 0, 0)
    else
        print('Part is unanchored')
    end
    

Events

  1. Definition: Code that runs in response to actions/events.
  2. Example: Touch event for a kill brick.
    • killBrick.Touched:Connect(function(touchPart) ... end)
  3. Using Object Browser: Find events & properties.

Random Numbers

  1. Random Wait Time: task.wait(math.random(1, 10))

Loops

  1. For Loops:
    • Example: Scale part over time.
    for i = 1, 10 do
        part.Size = Vector3.new(part.Size.X + 1, part.Size.Y, part.Size.Z)
        task.wait(0.5)
    end
    
  2. While Loops:
    • Example: While true do.
    while true do
        -- Your code here
        task.wait(0)
    end
    

Tables

  1. Definition: Used to store large amounts of data in key-value pairs.
  2. Example:
    local fruits = { bananas = 1, apples = 5, oranges = 2 }
    print(fruits.bananas) -- Outputs: 1
    
  3. Using Tables with For Loops: Loop through tables with in pairs.

Full Example: Building an Obby Game

  1. Create Kill Bricks: Add touch events.
  2. Create Checkpoints: Use leaderstats to save player progress.
  3. Combine Everything: Practice by building a complete Obby game.
  4. Debugging & Testing: Continuously test and debug your game.

Additional Resources

  • Developer Hub: Use Roblox Developer Hub for more documentation and tutorials.
  • Forums & Scripting Helpers: Seek help from forums and helper sites.

Conclusion

  • Motivation: Keep practicing; scripting has a steep but rewarding learning curve.
  • Next Steps: Apply these basics to more complex projects gradually.