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 = workspaceA 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
EasyBuild a platform across the gap from your script: the starter makes a new Part with the wrong values.
- Change the values: Size
Vector3.new(6, 1, 28)and PositionVector3.new(0, 10, 0). - Add
platform.Anchored = trueso it does not fall. - Add
platform.Parent = workspacelast, 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
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler