Menu
CoddyTech

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 right
  • Y: up and down
  • Z: 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 icon

Challenge

Easy

There 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.

The last line of the script sets the bridge's Size. Change its Z, the third number, so the bridge reaches both sides: at least 24. Keep it 6 wide and 1 thick.

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
bridge.Size = Vector3.new(6, 1, 4)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler