Stretch the Bridge
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 3 of 25.
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 bridge = script.Parent
print(bridge.Size)
bridge.Size = Vector3.new(8, 1, 10)The print shows the size before the change, for example 4, 1, 2. The next line makes the bridge 8 wide, 1 thick and 10 long. A part grows equally in both directions from its center, so the bridge now reaches 5 studs forward and 5 studs back from its Position.
You read one number with .X, .Y or .Z: bridge.Size.Z is 10.
Challenge
EasyStretch the wooden bridge across the 24 stud gap to the yellow goal.
- Find the last line:
bridge.Size = Vector3.new(6, 1, 4). - Change the third number, Z, to
28. Keep it 6 wide and 1 thick.
Press Play: the bridge reaches the goal and you can 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
bridge.Size = Vector3.new(6, 1, 4)
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