Menu
CoddyTech

Moving Platform

Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 21 of 24.

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

The blue platform should glide between Z 10 and Z -10 and keep going. The script tweens it there once.

Change only the TweenInfo so the platform:

  • takes 3 seconds each way, with Sine InOut easing
  • comes back after reaching the end
  • never stops

Press Play to watch it, 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()
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