Advertisement
Guest User

Untitled

a guest
May 25th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1.  
  2. function map(x, in_min, in_max, out_min, out_max)
  3. return out_min + (x - in_min)*(out_max - out_min)/(in_max - in_min)
  4. end
  5.  
  6. function TorusFun()
  7. local Base = script.Parent -- The tubemaker block
  8. local radius = 50
  9. local sliceamount = 70 -- How many slices in a torus
  10. local slicedistance = 360 / sliceamount -- multiplied by sliceamount should be equal to 360
  11.  
  12. for i = 1, sliceamount do -- create a circle of new base parts
  13. local ubase = Instance.new("Part")
  14. ubase.Name = "TubePart "..i -- Tubepart1, Tubepart2, ...
  15. ubase.Size = Vector3.new(1,1,1)
  16. ubase.Transparency = 1
  17. ubase.CanCollide = false
  18. ubase.Anchored = false -- anchored is false, necessary for welds to work (who knew?)
  19. ubase.Parent = script.Parent
  20. ubase.CFrame = Base.CFrame
  21. * CFrame.Angles(0, math.rad(i)*slicedistance, 0)
  22. * CFrame.new(0, 0, radius)
  23.  
  24. local weldbase = Instance.new("WeldConstraint")
  25. weldbase.Parent = Base
  26. weldbase.Part0 = Base
  27. weldbase.Part1 = ubase
  28.  
  29. for j = 1, 10 do
  30. local newPart = Instance.new("Part")
  31. newPart.Size = Vector3.new(4.5,0.5,0.5)
  32. newPart.TopSurface = "Smooth"
  33. newPart.BottomSurface = "Smooth"
  34. newPart.Parent = script.Parent:FindFirstChild("TubePart "..i, false)
  35. newPart.Anchored = false
  36. newPart.CFrame = ubase.CFrame
  37. * CFrame.new(0, 20, 0)
  38. * CFrame.Angles(math.rad(80) - math.rad(j)*15.5, 0, 0)
  39. * CFrame.new(0, -5, 0)
  40.  
  41. local weld = Instance.new("WeldConstraint")
  42. weld.Parent = ubase
  43. weld.Part0 = ubase
  44. weld.Part1 = newPart
  45.  
  46.  
  47. end
  48. end
  49.  
  50. local Ball = Instance.new("Part") -- A ball
  51. Ball.Size = Vector3.new(6,6,6)
  52. Ball.Shape = "Ball"
  53. Ball.CFrame = Base.CFrame
  54. * CFrame.new(0, 20, radius)
  55. Ball.Parent = script.Parent
  56. Ball.Anchored = false
  57. Ball.Velocity = Vector3.new(-50,0,0)
  58.  
  59.  
  60. script.Parent.ClickDetector:Destroy()
  61.  
  62. local c = Base.CFrame
  63. local counter = 0
  64. while true do
  65. -- follows the ball
  66. --Base.CFrame = CFrame.new(Base.Position, Vector3.new(Ball.Position.X, 0, Ball.Position.Z))
  67.  
  68. counter = counter + 0.015
  69.  
  70. Base.CFrame = c
  71. * CFrame.Angles(
  72. map(math.cos(counter), -1, 1, math.rad(355), math.rad(365) ),
  73. 0,
  74. map(math.sin(counter), -1, 1, math.rad(355), math.rad(365) )
  75. )
  76. wait(0.01)
  77. end
  78. end
  79.  
  80.  
  81.  
  82. script.Parent.ClickDetector.mouseClick:connect(TorusFun)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement