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:
- time in seconds
- easing style, such as
Enum.EasingStyle.Sine: how the speed changes along the way - easing direction:
In,OutorInOut - repeat count: how many extra times to play,
-1for forever - reverses:
trueto play backwards after each run - 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
MediumThe 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
SineInOuteasing - 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()
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
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