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!
Preparation: what you will need
Roblox Studio — a program for creating games (download from the official Roblox website, if you have not already done so)
Basic understanding of the interface - where the Explorer and Properties window is located
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
Open Roblox Studio and create a new project (Baseplate is perfect)
In the window Explorer find Workspace
Right-click on Workspace → Insert Object → Part
You have a gray block on the stage!
Step 2: Add the script
Right-click on your Part in Explorer
Choose Insert Object → Script
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
endStep 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)towait(0.5)— the colors will change fasterAdd your colors to the array
colorsChange
light.Brightnessto 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!
