Row of Pillars
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 5 of 24.
To make five pillars you could copy the same lines five times. A for loop runs them for you, as many times as you ask:
for i = 1, 3 do
print(i)
endThis prints 1, then 2, then 3. Everything between do and end runs once per round, and i holds the round number.
Because i changes every round, you can use it in a Position and each copy lands somewhere new:
for i = 1, 3 do
local ball = Instance.new("Part")
ball.Shape = Enum.PartType.Ball
ball.Position = Vector3.new(i * 10, 20, 0)
ball.Parent = workspace
endThree balls drop from X 10, 20 and 30: i * 10 is 10, then 20, then 30.
Challenge
EasyThe script makes one pillar at X 6. Turn it into a row of 5:
- Wrap the pillar code in
for i = 1, 5 do ... end. - Print
iat the start of each round. - Change the Position to
Vector3.new(i * 6, 4, 0), so the pillars stand at X 6, 12, 18, 24 and 30.
Press Play and walk between them, then Check.
Try it yourself
-- This makes ONE pillar. Make 5, in a row.
local pillar = Instance.new("Part")
pillar.Name = "Pillar"
pillar.Size = Vector3.new(2, 8, 2)
pillar.Position = Vector3.new(6, 4, 0)
pillar.Anchored = true
pillar.Parent = workspace
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Roblox Game Scripting
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler