Advertisement
OEAgamer1

Moving Platforms

May 5th, 2025
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. -- ___  ___  ___                              _
  2. --| . || __>| . | ___  ___ ._ _ _  ___  _ _ / |
  3. --| | || _> |   |/ . |<_> || ' ' |/ ._>| '_>| |
  4. --`___'|___>|_|_|\_. |<___||_|_|_|\___.|_|  |_|
  5. --               <___'                        
  6. -- -> YT: OEAgamer1
  7.  
  8. local travelInterval = 4
  9. local velocityCap = 30
  10. local angularVelocityCap = 3
  11. local shouldRemoveTargets = true
  12.  
  13. local container = script.Parent
  14. local mover = container:FindFirstChild("Platform")
  15. local positionController = mover:FindFirstChild("AlignPosition")
  16. local orientationController = mover:FindFirstChild("AlignOrientation")
  17.  
  18. local pathPoints = {}
  19.  
  20. repeat
  21.     local nextTarget = nil
  22.     local smallestIndex = math.huge
  23.  
  24.     for _, element in ipairs(container:GetChildren()) do
  25.         if element:IsA("BasePart") then
  26.             local parts = string.split(element.Name, " ")
  27.             local prefix, number = parts[1], tonumber(parts[2])
  28.             if string.lower(prefix) == "destination" and number and number < smallestIndex then
  29.                 smallestIndex = number
  30.                 nextTarget = element
  31.             end
  32.         end
  33.     end
  34.  
  35.     if nextTarget then
  36.         table.insert(pathPoints, nextTarget.CFrame)
  37.         if shouldRemoveTargets then
  38.             nextTarget:Destroy()
  39.         else
  40.             nextTarget.Name = "Target"
  41.         end
  42.     end
  43. until not nextTarget
  44.  
  45. positionController.MaxVelocity = velocityCap
  46. orientationController.MaxAngularVelocity = angularVelocityCap
  47. positionController.Position = pathPoints[1].Position
  48. orientationController.CFrame = pathPoints[1].Rotation
  49. mover.Anchored = false
  50.  
  51. while true do
  52.     for i = 1, #pathPoints do
  53.         local frame = pathPoints[i]
  54.         positionController.Position = frame.Position
  55.         orientationController.CFrame = frame.Rotation
  56.         task.wait(travelInterval)
  57.     end
  58. end
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement