Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. buttonpressed = false
  2.  
  3. local Part = script.Parent.Parent -- this is the Part we will move
  4. local newPos = Vector3.new(-18.45, 17.878, 51.1) -- the position the Part will go to
  5. local Time = 10 -- the time that the script will take to move the part
  6. local Increment = 0.1 -- the Part will move 0.5 studs each time it moves
  7. local active = false
  8.  
  9. local Diff = newPos - Part.Position -- the difference between the two positions
  10. local Mag = Diff.magnitude -- the distance between the two parts
  11. local Direction = CFrame.new(Part.Position, newPos).lookVector
  12.  
  13. local active = false
  14.  
  15. function MovePart() -- function to move the Part
  16. if not buttonpressed then
  17. buttonpressed = true
  18. if active == false then
  19. for n = 0, Mag, Increment do
  20. Part.CFrame = Part.CFrame + (Direction * Increment)
  21. wait( (Time/Mag) * Increment )
  22. active = true
  23. end
  24. elseif active == true then
  25. for n = 0, Mag, Increment do
  26. Part.CFrame = Part.CFrame - (Direction * Increment)
  27. wait( (Time/Mag) * Increment )
  28. active = true
  29. end
  30. end
  31. end
  32. buttonpressed = false
  33. end
  34.  
  35. script.Parent.MouseClick:connect(MovePart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement