Stretch the Bridge
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 3 of 24.
Every part has a Size and a Position. Both are a Vector3: three numbers for the three directions of the world.
X: left and rightY: up and downZ: forward and back
Distances in Roblox are measured in studs. A player is about 5 studs tall.
local box = script.Parent
print(box.Size)
box.Size = Vector3.new(4, 10, 4)The first print shows the size before the change, for example 2, 2, 2. The next line makes the box a tall tower: 4 wide, 10 high and 4 deep. A part grows equally in both directions from its center, so the tower now reaches 5 studs above and below its Position.
You read one number with .X, .Y or .Z: box.Size.Y is 10.
Challenge
EasyThere is a 24 stud gap between the gray spawn platform and the yellow goal, and the wooden bridge is only 4 studs long. There is no floor: miss the bridge and you fall.
Change the bridge's Size so it reaches both sides. Keep it 6 wide and 1 thick, and make it at least 24 long on Z.
Press Play and walk across, then Check.
Try it yourself
local bridge = script.Parent
-- The bridge is 6 wide, 1 thick and only 4 long.
print(bridge.Size)
-- Make it long enough to reach both sides
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