Advertisement
IiIDriversIiI

[Roblox] Turrets Script

May 13th, 2018
2,408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. me = game.Players.LocalPlayer
  2.  
  3.  
  4. h = Instance.new("HopperBin",me.Backpack)
  5. h.Name = "Turrets"
  6. script.Parent = h
  7.  
  8. bin = script.Parent
  9.  
  10. function prop(part, parent, collide, tran, ref, x, y, z, color, anchor)
  11. part.Parent = parent
  12. part.formFactor = 0
  13. part.CanCollide = collide
  14. part.Transparency = tran
  15. part.Reflectance = ref
  16. part.Size = Vector3.new(x,y,z)
  17. part.BrickColor = BrickColor.new(color)
  18. part.TopSurface = 0
  19. part.BottomSurface = 0
  20. part.Anchored = anchor
  21. part:BreakJoints()
  22. end
  23.  
  24. function weld(w, p, p0, p1, a, b, c, x, y, z)
  25. w.Parent = p
  26. w.Part0 = p0
  27. w.Part1 = p1
  28. w.C1 = CFrame.fromEulerAnglesXYZ(a,b,c) * CFrame.new(x,y,z)
  29. end
  30.  
  31. function mesh(mesh, parent, x, y, z, type)
  32. mesh.Parent = parent
  33. mesh.Scale = Vector3.new(x, y, z)
  34. mesh.MeshType = type
  35. end
  36.  
  37. function placeturret(mainplace)
  38. local turret = Instance.new("Model",workspace)
  39. turret.Name = "Turret"
  40.  
  41. local main = Instance.new("Part")
  42. prop(main, turret, true, 0, 0, 3, 1, 3, "Dark grey", true)
  43. main.CFrame = CFrame.new(mainplace)
  44. mainmesh = Instance.new("CylinderMesh",main)
  45.  
  46. local neck = Instance.new("Part")
  47. prop(neck,turret,true,0,0,1,2,1,"Dark grey", true)
  48. neck.CFrame = CFrame.new(mainplace) * CFrame.new(0,1.1,0)
  49. neckmesh = Instance.new("CylinderMesh",neck)
  50. neckmesh.Scale = Vector3.new(1,1.5,1)
  51.  
  52. local move = Instance.new("Part")
  53. prop(move, turret, false, 0, 0, 1, 1, 5,"Dark grey", false)
  54. move.CFrame = CFrame.new(mainplace) * CFrame.new(0,3,0)
  55.  
  56. local bg = Instance.new("BodyGyro")
  57. bg.Parent = move
  58. bg.maxTorque = Vector3.new(1e+008,1e+008,1e+008)
  59.  
  60. local bp = Instance.new("BodyPosition",move)
  61. bp.maxForce = Vector3.new(1e+008,1e+008,1e+008)
  62. bp.position = bp.Parent.Position
  63.  
  64. local gunner = Instance.new("Part")
  65. gunner.FrontSurface = "Hinge"
  66. prop(gunner,turret,true,0,0,1,1,1,"Dark grey",false)
  67. gunner.CFrame = CFrame.new(mainplace) * CFrame.new(0,3,2.5)
  68.  
  69. local gunweld = Instance.new("Weld")
  70. weld(gunweld,move,move,gunner,0,0,0,0,0,2.5)
  71.  
  72. local sound = Instance.new("Sound",gunner)
  73. sound.Volume = 0.8
  74. sound.Pitch = 4
  75. sound.SoundId = "http://www.roblox.com/asset/?id=2760979"
  76.  
  77. function find(pos)
  78. local list = game.Workspace:children()
  79. local torso = nil
  80. local dist = 40
  81. local temp = nil
  82. local human = nil
  83. local temp2 = nil
  84. for x = 1, #list do
  85. temp2 = list[x]
  86. if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  87. temp = temp2:findFirstChild("Torso")
  88. human = temp2:findFirstChild("Humanoid")
  89. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  90. if (temp.Position - pos).magnitude < dist then
  91. torso = temp
  92. dist = (temp.Position - pos).magnitude
  93. end
  94. end
  95. end
  96. end
  97. return torso
  98. end
  99.  
  100. coroutine.resume(coroutine.create(function()
  101. while true do
  102. if gunner.Parent ~= nil then
  103. wait(0.1)
  104. local target = find(gunner.Position)
  105. if target ~= nil then
  106. bg.cframe = CFrame.new(move.Position, target.Position)
  107. local meh = math.random(1,6)
  108. if meh == 1 then
  109. local bulls = {}
  110. local dis = (gunner.Position - target.Position).magnitude
  111. local bullet = Instance.new("Part")
  112. prop(bullet,workspace,false,0,0,1,1,1,"Bright yellow",true)
  113. bullet.CFrame = CFrame.new(gunner.Position, target.Position) * CFrame.new(0,0,-dis/2)
  114. local meu = Instance.new("SpecialMesh")
  115. mesh(meu,bullet,0.23,0.23,dis,"Brick")
  116. local huo = target.Parent:findFirstChild("Humanoid")
  117. huo:TakeDamage(math.random(huo.MaxHealth/34,huo.MaxHealth/8))
  118. local randompitch = math.random(500,1200)/1000
  119. sound.Pitch = randompitch
  120. sound:play()
  121. table.insert(bulls,bullet)
  122. for i=1, math.random(3,6) do
  123. local msi = math.random(8,23)/10
  124. local th = Instance.new("Part")
  125. prop(th,workspace,false,0,0,1,1,1,"Bright yellow",true)
  126. th.CFrame = CFrame.new(gunner.Position,target.Position) * CFrame.new(0,0,-dis)
  127. th.CFrame = th.CFrame * CFrame.Angles(math.random(-100,100),math.random(-100,100),math.random(-100,100))
  128. th.CFrame = th.CFrame * CFrame.new(0,0,-msi/2)
  129. thme = Instance.new("SpecialMesh")
  130. mesh(thme,th,0.13,0.13,msi, "Brick")
  131. table.insert(bulls,th)
  132. for duh=1, math.random(2,5) do
  133. local bag = math.random(5,18)/10
  134. local bah = Instance.new("Part")
  135. prop(bah,workspace,false,0,0,1,1,1,"Bright yellow",true)
  136. bah.CFrame = CFrame.new(th.Position) * CFrame.new(0,0,msi/2)
  137. bah.CFrame = bah.CFrame * CFrame.Angles(math.random(-100,100),math.random(-100,100),math.random(-100,100))
  138. bah.CFrame = bah.CFrame * CFrame.new(0,0,-bag/2)
  139. bahme = Instance.new("SpecialMesh")
  140. mesh(bahme,bah,0.02,0.02,bag, "Brick")
  141. table.insert(bulls,bah)
  142. end
  143. end
  144. coroutine.resume(coroutine.create(function()
  145. for i=1, #bulls do
  146. coroutine.resume(coroutine.create(function()
  147. wait(0.1)
  148. for k=0, 1, 0.25 do
  149. wait()
  150. bulls[i].Transparency = k
  151. end
  152. bulls[i]:remove()
  153. end))
  154. end
  155. end))
  156. end
  157. end
  158. end
  159. end
  160. end))
  161. end
  162.  
  163. bin.Selected:connect(function(mouse)
  164. mouse.Button1Down:connect(function()
  165. placeturret(mouse.Hit.p)
  166. end)
  167. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement