Menu
CoddyTech

Build a Platform

Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 4 of 25.

Scripts can build the world too. Instance.new makes a new object, and you set its properties before you put it in the game:

local ball = Instance.new("Part")
ball.Name = "Ball"
ball.Shape = Enum.PartType.Ball
ball.Position = Vector3.new(0, 20, 0)
ball.Parent = workspace

A new part is not in the world until its Parent is set to workspace. Setting Parent last means the part shows up already finished.

A new part is also not anchored: gravity pulls it down and it falls. The ball above drops from height 20 onto the ground. A part with Anchored = true stays exactly where you put it, which is what you want for floors, walls and platforms.

challenge icon

Challenge

Easy

Build a platform across the gap from your script: the starter makes a new Part with the wrong values.

  1. Change the values: Size Vector3.new(6, 1, 28) and Position Vector3.new(0, 10, 0).
  2. Add platform.Anchored = true so it does not fall.
  3. Add platform.Parent = workspace last, so it appears.

Press Play: a platform spans the gap and you can walk to the goal. Then Check.

Try it yourself

local platform = Instance.new("Part")

-- 1. Change the values: Size 6, 1, 28 and Position 0, 10, 0
platform.Name = "Platform"
platform.Size = Vector3.new(4, 1, 2)
platform.Position = Vector3.new(0, 0, 0)

-- 2. Keep it from falling: Anchored

-- 3. Put it in the world, last: Parent

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler