Staircase Builder
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 6 of 24.
In the last lesson i moved each pillar along one direction. A staircase needs every step to go up and forward at the same time, so i goes into two of the three numbers.
Say each step is 1 stud thick. For step i to have its top at height i, its center must be half a stud lower: i - 0.5. To move each step 2 studs closer to the goal along Z, subtract i * 2 from where you start:
for i = 1, 3 do
print(i - 0.5, 10 - i * 2)
endThis prints 0.5 8, 1.5 6 and 2.5 4: the Y and Z of three steps climbing toward Z 0. print with several values separates them with a space.
In this game a player walks up a step about 1 stud high; anything taller needs a jump.
Challenge
EasyThe yellow block is 10 studs tall: too high to jump. Build a staircase up to it.
The loop already makes 10 anchored steps named Step, but they are all in the same spot. Change their Position so that step i:
- has its top at height
i(a step is 1 thick, so its center Y isi - 0.5) - is at Z
10 - i * 2, so each step is 2 studs closer to the block
Press Play and climb, then Check.
Try it yourself
for i = 1, 10 do
local step = Instance.new("Part")
step.Name = "Step"
step.Size = Vector3.new(6, 1, 2)
step.Anchored = true
-- Each step is 1 stud higher and 2 studs closer to the yellow block
step.Position = Vector3.new(0, 0.5, 10)
step.Parent = workspace
end
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