Menu
CoddyTech

Moving Platform

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

TweenInfo.new takes more than the time. Its values, in order:

  1. time in seconds
  2. easing style, such as Enum.EasingStyle.Sine: how the speed changes along the way
  3. easing direction: In, Out or InOut
  4. repeat count: how many extra times to play, -1 for forever
  5. reverses: true to play backwards after each run
  6. delay: seconds to wait before it starts
local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 2, false)

This one plays 3 times (once, plus 2 repeats), each run taking 1 second, jumping back to the start between runs.

Sine with InOut starts slowly, speeds up in the middle and slows down at the end, the natural way for a platform to move. Linear keeps one speed the whole way.

A tweened platform does not carry players sideways: they have to walk with it.

challenge icon

Challenge

Medium

Make the blue platform glide between Z 10 and Z -10 forever.

  1. Change only the TweenInfo.new line. Keep 3 seconds and Sine InOut.
  2. Add a repeat count of -1 (forever) and reverses true, so it comes back.

Press Play: the platform glides back and forth without stopping. Then Check.

Try it yourself

local TweenService = game:GetService("TweenService")
local platform = script.Parent

-- TweenInfo.new(time, style, direction, repeatCount, reverses)
local info = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local goal = { Position = Vector3.new(0, 10, -10) }

local tween = TweenService:Create(platform, info, goal)
tween:Play()

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler