Skinstashery
Roblox
Home / Roblox / Studio script library / Moving platform
RB-004

Roblox moving platform script

A platform that slides back and forth between two points using TweenService.

Script type
Script
Where it goes
Inside the platform Part
Category
World and effects

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Moving platform: slides from its start position to START + OFFSET and back.

local OFFSET = Vector3.new(0, 0, 40)   -- how far to move (x, y, z in studs)
local TRAVEL_TIME = 4                  -- seconds for one trip
local WAIT_AT_ENDS = 1                 -- seconds to pause at each end

local TweenService = game:GetService("TweenService")

local platform = script.Parent
platform.Anchored = true

local startPosition = platform.Position
local endPosition = startPosition + OFFSET

local info = TweenInfo.new(TRAVEL_TIME, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local forward = TweenService:Create(platform, info, { Position = endPosition })
local backward = TweenService:Create(platform, info, { Position = startPosition })

while true do
	forward:Play()
	forward.Completed:Wait()
	task.wait(WAIT_AT_ENDS)

	backward:Play()
	backward.Completed:Wait()
	task.wait(WAIT_AT_ENDS)
end

How to set it up

  1. Insert a flat Part for the platform.
  2. Add a Script inside it and paste the code.
  3. Put the platform where you want it to start. The code reads its position when the game starts.
  4. Play and jump on. Players ride on top of it.

Change it

More in World and effects

All Roblox scripts

More Roblox tools