Guest User

drone that detects ore

a guest
Feb 4th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1.  
  2.  
  3.  
  4. local drone = script.Parent.Parent
  5. local eng = script.Parent.Engine
  6. local trail = script.Parent.Fire
  7. local track = script.Parent.Track
  8. local target = ""
  9. local backup = drone:Clone()
  10. local parts = {track, eng, trail}
  11. local c = drone.BodyKit:GetChildren()
  12. for i = 1, #c do
  13. table.insert(parts, c[i])
  14. end
  15.  
  16.  
  17. function found(maxDistance)
  18. if connection ~= nil then
  19. connection:disconnect()
  20. end
  21.  
  22. local c = game.Workspace:GetChildren()
  23. local ore = {}
  24. for i = 1, #c do
  25. if c[i]:FindFirstChild("Htitanium") ~= nil and c[i] ~= target and c[i].Htitanium.Health > 0 then
  26. table.insert(ore, c[i])
  27.  
  28.  
  29. end
  30. end
  31.  
  32.  
  33.  
  34.  
  35.  
  36. local a = 100
  37.  
  38. for i = 1, #ore do
  39.  
  40. local dist = (ore[i].Ore.Position - eng.Position).magnitude
  41. if dist < a then
  42. a = dist
  43. end
  44. end
  45.  
  46.  
  47. for i = 1, #ore do
  48.  
  49. if(ore[i].Ore.Position - eng.Position).magnitude == a then
  50. target = ore[i]
  51.  
  52. end
  53. end
  54.  
  55. connection = target.Htitanium.Died:connect(found)
  56. end
  57.  
  58.  
  59.  
  60. function clean()
  61. wait(0.5)
  62. script.Parent = workspace
  63. drone:Remove()
  64. local c = backup:Clone()
  65. wait(2.5)
  66. c.Parent = workspace
  67. c:MakeJoints()
  68. script:Remove()
  69. end
  70.  
  71.  
  72.  
  73. while true do
  74. if (eng.Position - track.Position).magnitude >= 10 then
  75. eng.BodyPosition.maxForce = Vector3.new(0,0,0)
  76. track:BreakJoints()
  77. for i = 1, #parts do
  78. parts[i].RotVelocity = Vector3.new(math.random(-25,25),math.random(-25,25),math.random(-25,25))
  79. parts[i].CFrame = eng.CFrame + Vector3.new(math.random(-2,2),math.random(-2,2),math.random(-2,2))
  80. local bv = Instance.new("BodyVelocity")
  81. bv.Parent = parts[i]
  82. bv.velocity = parts[i].Position - eng.Position
  83. end
  84. clean()
  85. break
  86. end
  87. eng.BodyPosition.position = eng.Position + eng.CFrame.lookVector
  88. found()
  89. if target ~= "" then
  90.  
  91. eng.BodyGyro.cframe = CFrame.new(eng.Position, target.Ore.Position)
  92.  
  93. end
  94.  
  95. wait(0.1)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment