{}const=>[]async()letfn</>var
DevelopmentLua

Roblox Lua for beginners: write your first working script in 10 minutes

A simple guide without water: create a glowing block with effects and learn the basics of Lua. Copy the code, run it, and watch your game come to life right before your eyes!

К

Kodik

Author

4 min read

Hi!

If you are just starting to understand how to create games in Roblox, then this article is for you. Today we will write your first working script in Lua, which you can run right now. No water — just practice!

What is Lua and why is it used in Roblox?

Lua is a simple and fast programming language that Roblox chose to create game logic. It is lighter than many other languages and is great for beginners. If you can write a simple sentence in Russian, then you can write code in Lua!

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

Preparation: what you will need

  1. Roblox Studio — a program for creating games (download from the official Roblox website, if you have not already done so)

  2. Basic understanding of the interface - where the Explorer and Properties window is located

  3. 5-10 minutes of free time and the desire to create something cool!

Your first script: a glowing block

Let's create something simple but impressive — a block that will change color and glow. This will teach you the basics of working with scripts.

Step 1: Create an object

  1. Open Roblox Studio and create a new project (Baseplate is perfect)

  2. In the window Explorer find Workspace

  3. Right-click on Workspace → Insert ObjectPart

  4. You have a gray block on the stage!

Step 2: Add the script

  1. Right-click on your Part in Explorer

  2. Choose Insert ObjectScript

  3. Double-clicking on the script will open the code editor

Step 3: Write the code

Remove the line print("Hello world!") and insert this code:

-- Получаем ссылку на наш блок
local part = script.Parent

-- Создаём эффект свечения
local light = Instance.new("PointLight")
light.Parent = part
light.Brightness = 2
light.Range = 20

-- Цвета для смены
local colors = {
    Color3.fromRGB(255, 0, 0),    -- Красный
    Color3.fromRGB(0, 255, 0),    -- Зелёный
    Color3.fromRGB(0, 0, 255),    -- Синий
    Color3.fromRGB(255, 255, 0),  -- Жёлтый
    Color3.fromRGB(255, 0, 255)   -- Фиолетовый
}

-- Бесконечный цикл смены цветов
while true do
    for i = 1, #colors do
        part.BrickColor = BrickColor.new(colors[i])
        light.Color = colors[i]
        wait(1)  -- Ждём 1 секунду
    end
end

Step 4: Launch!

Click on the green button Play in the top panel. Your block should start changing colors every second and glow!

🎉 Congratulations, you just wrote your first working script!

Let's analyze the code: what's going on here?

Let's see what each part does:

Comments (lines with --) are notes for you, the computer ignores them.

script.Parent is a way to refer to the object in which the script is located. In our case, it is Part.

Instance.new() - creates a new object. We created PointLight (a point source of light).

Colors array — a list of five colors. Color3.fromRGB() creates a color from the red, green, and blue channels (values from 0 to 255).

while true do — an infinite loop. The code inside will be executed over and over again.

for i = 1, #colors do — a loop that runs through all the colors in the array. #colors returns the number of elements.

wait(1) — pause for 1 second. Without it, everything would change instantly!

Experiments: make the script your own

Now try to change the script and see what happens:

  • Change wait(1) to wait(0.5) — the colors will change faster

  • Add your colors to the array colors

  • Change light.Brightness to a larger number (for example, 5)

  • Try resizing the block: part.Size = Vector3.new(4, 4, 4)

Common mistakes and how to fix them

The script does not run? Make sure you created a regular Script, not a LocalScript or ModuleScript.

Doesn't the block change color? Make sure the script is inside the Part (it must be a child element).

Error in the console? Carefully check your code with the example — perhaps a comma or bracket is missing.

You can learn Lua for Roblox and much more in Codice - our educational platform, where we analyze game creation, programming and web development in simple language with clear examples.

And we also have a cool Telegram channel with a friendly community! There we share useful tips, discuss projects and help each other grow as developers. Join us!

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card