HowToRoblox

EscalatorHandler

Jul 17th, 2021 (edited)
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. local steps = script.Parent:WaitForChild("Steps"):GetChildren()
  2.  
  3.  
  4. table.sort(steps, function(a, b)
  5.  
  6.     return a.Position.Y < b.Position.Y
  7. end)
  8.  
  9.  
  10. local startPos = steps[1].Position
  11.  
  12. local endY = startPos.Y + (#steps - 1) * steps[1].Size.Y
  13.  
  14.  
  15. local speed = 1
  16.  
  17.  
  18. local ts = game:GetService("TweenService")
  19. local ti = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  20.  
  21.  
  22.  
  23. while wait(speed) do
  24.  
  25.     for i, step in pairs(steps) do
  26.        
  27.        
  28.         local y, z = (1 / speed) * step.Size.Y, (1 / speed) * step.Size.Z
  29.  
  30.         step.Velocity = Vector3.new(0, y, z)
  31.  
  32.  
  33.         if math.floor(step.Position.Y + 0.5) >= math.floor(endY) then
  34.  
  35.             step.Position = startPos
  36.         end
  37.  
  38.  
  39.         local tween = ts:Create(step, ti, {Position = step.Position + Vector3.new(0, step.Size.Y, step.Size.Z)})
  40.  
  41.         tween:Play()
  42.     end
  43. end
Add Comment
Please, Sign In to add comment