InfMods

moving part script easy roblox

Sep 23rd, 2022
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. step 1: create a part add a local script
  2.  
  3. step 2: copy script
  4.  
  5.  
  6. -- Positions can be obtained by going into the properties of the parent part
  7. -- Position 1 - This is your initial position
  8. local position1 = Vector3.new(36,7.5,8)
  9. -- Position 2 - This is your goal position
  10. local position2 = Vector3.new(36,16,8)
  11.  
  12. -- This variable modulates between 0 and 1
  13. local factor = 0
  14.  
  15. -- These variables keep track of the part we're moving and the service we'll be getting for running our function
  16. local this = script.Parent
  17. local RunService = game:GetService("RunService")
  18.  
  19. -- This function moves the platform
  20. function movePlatform (time, step)
  21. -- This is the code for calculating the factor. This is a sine function that modulates between 0 and 1.
  22. factor = 0.5 * math.sin(time) + 0.5
  23.  
  24. -- This is a lerp function. Lerp interpolates between two positions by the factor given (0 is the initial, 1 is the goal).
  25. local finalPosition = position1:Lerp(position2, factor)
  26.  
  27. -- This sets the part's position to our newly-created position
  28. this.CFrame = CFrame.new(finalPosition)
  29. end
  30.  
  31. -- This connects our function to the RunService so that our function can run every frame.
  32. RunService.Stepped:Connect(movePlatform)
Advertisement
Add Comment
Please, Sign In to add comment