Advertisement
spacemonkey3591

Moving Objects

Jun 15th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1.  
  2. local runDummyScript = function(f,scri)
  3. local oldenv = getfenv(f)
  4. local newenv = setmetatable({}, {
  5. __index = function(_, k)
  6. if k:lower() == 'script' then
  7. return scri
  8. else
  9. return oldenv[k]
  10. end
  11. end
  12. })
  13. setfenv(f, newenv)
  14. ypcall(function() f() end)
  15. end
  16. cors = {}
  17. mas = Instance.new("Model",game:GetService("Lighting"))
  18. mas.Name = "CompiledModel"
  19. o1 = Instance.new("Model")
  20. o2 = Instance.new("Part")
  21. o3 = Instance.new("Part")
  22. o4 = Instance.new("Part")
  23. o5 = Instance.new("IntValue")
  24. o6 = Instance.new("Script")
  25. o7 = Instance.new("IntValue")
  26. o8 = Instance.new("Script")
  27. o9 = Instance.new("Part")
  28. o10 = Instance.new("Part")
  29. o1.Parent = mas
  30. o2.Parent = o1
  31. o2.BrickColor = BrickColor.new("Really black")
  32. o2.Position = Vector3.new(-6.80000305, 0.49999994, 76.2000122)
  33. o2.Anchored = true
  34. o2.Shape = Enum.PartType.Ball
  35. o2.Size = Vector3.new(1.39999998, 1.39999998, 1.39999998)
  36. o2.CFrame = CFrame.new(-6.80000305, 0.49999994, 76.2000122, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  37. o2.BottomSurface = Enum.SurfaceType.Smooth
  38. o2.TopSurface = Enum.SurfaceType.Smooth
  39. o2.Color = Color3.new(0.0666667, 0.0666667, 0.0666667)
  40. o2.Position = Vector3.new(-6.80000305, 0.49999994, 76.2000122)
  41. o3.Parent = o1
  42. o3.BrickColor = BrickColor.new("Really black")
  43. o3.Position = Vector3.new(-6.80000305, 0.599999964, 74.0999985)
  44. o3.Anchored = true
  45. o3.Shape = Enum.PartType.Ball
  46. o3.Size = Vector3.new(1.39999998, 1.39999998, 1.39999998)
  47. o3.CFrame = CFrame.new(-6.80000305, 0.599999964, 74.0999985, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  48. o3.BottomSurface = Enum.SurfaceType.Smooth
  49. o3.TopSurface = Enum.SurfaceType.Smooth
  50. o3.Color = Color3.new(0.0666667, 0.0666667, 0.0666667)
  51. o3.Position = Vector3.new(-6.80000305, 0.599999964, 74.0999985)
  52. o4.Name = "MovingPart"
  53. o4.Parent = o1
  54. o4.Position = Vector3.new(-8.00000286, 0.800000072, 75.2000046)
  55. o4.Anchored = true
  56. o4.Size = Vector3.new(3.6000011, 0.799999893, 1.20000005)
  57. o4.CFrame = CFrame.new(-8.00000286, 0.800000072, 75.2000046, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  58. o4.BottomSurface = Enum.SurfaceType.Smooth
  59. o4.TopSurface = Enum.SurfaceType.Smooth
  60. o4.Position = Vector3.new(-8.00000286, 0.800000072, 75.2000046)
  61. o5.Name = "Rate"
  62. o5.Parent = o4
  63. o6.Name = "MoveScript"
  64. o6.Parent = o4
  65. table.insert(cors,coroutine.create(function()
  66. wait()
  67. runDummyScript(function()
  68. --[[
  69.  
  70. Rate = How far left / right it goes; if it's 0, then it will decide randomly between two numbers (Edit in script).
  71. Speed = How many studs it moves per second; if the value is 1, it will move one stud every second; two if value is 2; etc.
  72.  
  73. --]]
  74.  
  75. local object = script.Parent
  76. local speed = object.Speed.Value
  77. local rate = object.Rate.Value
  78. local direction = Vector3.new(1, 0, 0)
  79.  
  80. part = {
  81. move = function() -- Makes it a method :D
  82. local s = 0.03
  83. for d = 0,1,s do
  84. object.CFrame = object.CFrame + Vector3.new(s * direction.X, 0, 0)
  85. if d % (speed / 10) == 0 then
  86.  
  87. wait()
  88. end
  89. end
  90. end
  91. }
  92.  
  93. while true do
  94. nRate = rate
  95. if nRate == 0 then
  96. nRate = math.random(2, 10)
  97. end
  98. direction = direction * -1
  99. for i = 1,nRate do
  100. part:move()
  101. end
  102. wait()
  103. end
  104.  
  105.  
  106. --direction = Vector3.new(0,0,1)
  107. -- part:move()
  108. end,o6)
  109. end))
  110. o7.Name = "Speed"
  111. o7.Parent = o4
  112. o7.Value = 20
  113. o8.Name = "WeldScript"
  114. o8.Parent = o1
  115. table.insert(cors,coroutine.create(function()
  116. wait()
  117. runDummyScript(function()
  118. function Weld(x, y)
  119. local weld = Instance.new("Weld")
  120. weld.Part0 = x
  121. weld.Part1 = y
  122. weld.C0 = x.CFrame:inverse() * CFrame.new(x.Position)
  123. weld.C1 = y.CFrame:inverse() * CFrame.new(x.Position)
  124. weld.Parent = x
  125. end
  126.  
  127. local prev
  128. local unanchor = {}
  129.  
  130. function search ( n )
  131. n = n or script.Parent
  132. for i, v in pairs(n:getChildren()) do
  133. if v:IsA("BasePart") then
  134. if prev then
  135. Weld(v, prev)
  136. prev = v
  137. unanchor[#unanchor + 0] = v
  138. else
  139. prev = v
  140. unanchor[#unanchor + 0] = v
  141. end
  142. end
  143. search(v)
  144. end
  145. end
  146.  
  147. function unanchormodel(m)
  148. local g = m:GetChildren()
  149. for i = 1, #g do
  150. if (g[i]:IsA("BasePart")) then
  151. g[i].Anchored = false
  152. elseif (g[i]:IsA("Model")) then
  153. unanchormodel(g[i])
  154. end
  155. end
  156. end
  157.  
  158.  
  159.  
  160. search()
  161. wait()
  162. unanchormodel(script.Parent)
  163.  
  164. end,o8)
  165. end))
  166. o9.Parent = o1
  167. o9.BrickColor = BrickColor.new("Really black")
  168. o9.Position = Vector3.new(-9.60000229, 0.699997783, 76.2000122)
  169. o9.Anchored = true
  170. o9.Shape = Enum.PartType.Ball
  171. o9.Size = Vector3.new(1.39999998, 1.39999998, 1.39999998)
  172. o9.CFrame = CFrame.new(-9.60000229, 0.699997783, 76.2000122, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  173. o9.BottomSurface = Enum.SurfaceType.Smooth
  174. o9.TopSurface = Enum.SurfaceType.Smooth
  175. o9.Color = Color3.new(0.0666667, 0.0666667, 0.0666667)
  176. o9.Position = Vector3.new(-9.60000229, 0.699997783, 76.2000122)
  177. o10.Parent = o1
  178. o10.BrickColor = BrickColor.new("Really black")
  179. o10.Position = Vector3.new(-9.60000229, 0.799999833, 74.0999985)
  180. o10.Anchored = true
  181. o10.Shape = Enum.PartType.Ball
  182. o10.Size = Vector3.new(1.39999998, 1.39999998, 1.39999998)
  183. o10.CFrame = CFrame.new(-9.60000229, 0.799999833, 74.0999985, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  184. o10.BottomSurface = Enum.SurfaceType.Smooth
  185. o10.TopSurface = Enum.SurfaceType.Smooth
  186. o10.Color = Color3.new(0.0666667, 0.0666667, 0.0666667)
  187. o10.Position = Vector3.new(-9.60000229, 0.799999833, 74.0999985)
  188. mas.Parent = workspace
  189. mas:MakeJoints()
  190. local mas1 = mas:GetChildren()
  191. for i=1,#mas1 do
  192. mas1[i].Parent = script
  193. ypcall(function() mas1[i]:MakeJoints() end)
  194. end
  195. mas:Destroy()
  196. for i=1,#cors do
  197. coroutine.resume(cors[i])
  198. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement