Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.04 KB | None | 0 0
  1. -----------------------------Variable-----------------------------
  2. turretpos = Vector3.new(0, 120, 0)
  3. avoid = {"Dimitriye98"}
  4. --------------------------Building Script--------------------------
  5. local m = Instance.new("Message")
  6. m.Parent = game.Workspace
  7. for i=2,100,2 do
  8.     m.Text = "Loading Turret Script: "..i.."%"
  9.     for x=2,i,2 do
  10.         m.Text = "|"..m.text.."|"
  11.     end
  12.     wait(0.1)
  13. end
  14. m.Text = "Initializing."
  15. for i=1,30 do
  16.     if i%3 == 1 then
  17.         m.Text = "Initializing."
  18.     else
  19.         m.Text = m.Text.."."
  20.     end
  21.     wait(0.5)
  22. end
  23. local waiting = true
  24. local launch = coroutine.create(function()
  25.     local n = 1
  26.     local m = m
  27.     while waiting do
  28.         if n%3 == 1 then
  29.             m.Text = "Launching."
  30.         else
  31.             m.Text = m.Text.."."
  32.         end
  33.         n = n+1
  34.         wait(0.5)
  35.     end
  36. end)
  37. coroutine.resume(launch)
  38. wait(10)
  39. local model = Instance.new("Model")
  40. model.Name = "Turret"
  41. local engine = Instance.new("Part")
  42. engine.Name = "Engine"
  43. engine.CFrame = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  44. engine.formFactor = 0
  45. engine.Size = Vector3.new(1, 1, 4)
  46. engine.BrickColor = BrickColor.new(1)
  47. engine.TopSurface = 0
  48. engine.BottomSurface = 0
  49. engine.Locked = true
  50. engine.Parent = model
  51. local hole = Instance.new("Hole")
  52. hole.FaceId = 5
  53. hole.Parent = engine
  54. local enginemesh = Instance.new("SpecialMesh")
  55. enginemesh.MeshType = 3
  56. enginemesh.Scale = Vector3.new(2, 2, 1)
  57. enginemesh.Parent = engine
  58. local gyro = Instance.new("BodyGyro")
  59. gyro.maxTorque = Vector3.new(9000, 9000, 9000)
  60. gyro.Parent = engine
  61. local hover = Instance.new("BodyPosition")
  62. hover.position = turretpos
  63. hover.maxForce = Vector3.new(9000, 9000, 9000)
  64. hover.Parent = engine
  65. local indicator = Instance.new("Part")
  66. indicator.Name = "StatusIndicator"
  67. indicator.BrickColor = BrickColor.new(26)
  68. indicator.formFactor = 2
  69. indicator.Size = Vector3.new(1, 0.4, 1)
  70. indicator.Locked = true
  71. indicator.BottomSurface = 0
  72. indicator.TopSurface = 0
  73. indicator.CFrame = CFrame.new(0, 0.699999988, -0.5, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  74. indicator.Parent = model
  75. local W = Instance.new("Weld")
  76. W.Part0 = engine
  77. W.Part1 = indicator
  78. local CJ = CFrame.new(engine.Position)
  79. local C0 = engine.CFrame:inverse()*CJ
  80. local C1 = indicator.CFrame:inverse()*CJ
  81. W.C0 = C0
  82. W.C1 = C1
  83. W.Parent = engine
  84. local indicatormesh = Instance.new("SpecialMesh")
  85. indicatormesh.MeshType = 1
  86. indicatormesh.Scale = Vector3.new(1, 1.5, 1)
  87. indicatormesh.Parent = indicator
  88. engine.CFrame = CFrame.new(turretpos)
  89. model.archivable = false
  90. model.Parent = game.Workspace
  91. script.Parent = engine
  92. script.Name = "AimScript"
  93. --------------------------Control Script--------------------------
  94.  
  95. function move(target)
  96.     local dir = (target.Position - engine.Position).unit
  97.     local spawnPos = engine.Position
  98.     local pos = spawnPos + (dir * 1)
  99.     engine:findFirstChild("BodyGyro").cframe = CFrame.new(pos,  pos + dir)
  100.     engine:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000,9000,9000)
  101. end
  102.  
  103. function fireLaser(target)
  104.     local origin = script.Parent.Position+script.Parent.CFrame.lookVector*1.8
  105.     local dist = (origin - target).magnitude
  106.    
  107.     local part = Instance.new("Part")
  108.     part.Size = Vector3.new(1,dist,1)
  109.     part.CFrame = CFrame.new((origin + target)/2, target) * CFrame.fromEulerAnglesXYZ(math.pi/2,0,0)
  110.     part.BrickColor = BrickColor.new("Bright red")
  111.     part.Transparency = 0.5
  112.     part.TopSurface = 0
  113.     part.BottomSurface = 0
  114.     part.CanCollide = false
  115.     part.Anchored = true
  116.    
  117.     local mesh = Instance.new("CylinderMesh")
  118.     mesh.Scale = Vector3.new(0.5,1,0.5)
  119.     mesh.Parent = part
  120.  
  121.     coroutine.resume(coroutine.create(function(laser)
  122.     local trans = 1 - laser.Transparency
  123.  
  124.     for i=1,5 do
  125.         laser.Transparency = laser.Transparency + trans/5
  126.         wait(0.1)
  127.     end
  128.  
  129.     laser:remove()
  130. end), part)
  131.  
  132.     part.Parent = game.Workspace
  133.  
  134.     local explosion = Instance.new("Explosion")
  135.     explosion.Position = target
  136.     explosion.Parent = game.Workspace
  137. end
  138.  
  139. function checkName(name, table)
  140.     for i=1,#table do
  141.         if type(table[i]):lower() == "string" and table[i]:lower() == name:lower() then return true end
  142.     end
  143.     return false
  144. end
  145.  
  146. function findNearestTorso(pos)
  147.     list = game.Players:GetChildren()
  148.     torso = nil
  149.     human = nil
  150.     for i=1, #list do
  151.         if list[i].Character ~= nil and not checkName(list[i].Name, avoid) then
  152.             local temp = list[i].Character:findFirstChild("Torso")
  153.             human = list[i].Character:findFirstChild("Humanoid")
  154.             if temp ~= nil and human ~= nil and human.Health > 0 and human.Parent:findFirstChild("ForceField") == nil then
  155.                 if torso == nil or (temp.Position - pos).magnitude < (torso.Position - pos).magnitude then
  156.                     torso = temp
  157.                     dist = (temp.Position - pos).magnitude
  158.                 end
  159.             end
  160.         end
  161.     end
  162.     return torso
  163. end
  164.  
  165. waiting = false
  166. coroutine.yield(launch)
  167. m.Text = "Ready"
  168. game:getService("Debris"):addItem(m,3)
  169.  
  170. while true do
  171.     local torso = findNearestTorso(engine.Position)
  172.     if torso ~= nil then
  173.         indicator.BrickColor = BrickColor.new(37)
  174.         move(torso)
  175.         pos = torso.Position
  176.         wait(math.random(0.7, 1.3))
  177.         fireLaser(pos)
  178.         indicator.BrickColor = BrickColor.new(21)
  179.         wait(4.7)
  180.     else indicator.BrickColor = BrickColor.new(26) end
  181.     wait(0.3)
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement