Advertisement
KHSora455

Turret Script

Jul 15th, 2015
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. Turret Script
  2.  
  3. LOCAL SCRIPT: Go to line 4 and put your name where it says "Sora295"
  4.  
  5.  
  6. me = game.Players.Sora295
  7.  
  8.  
  9.  
  10. if script.Parent.className ~= "HopperBin" then
  11.  
  12. h = Instance.new("HopperBin",me.Backpack)
  13.  
  14. h.Name = "Turrets"
  15.  
  16. script.Parent = h
  17.  
  18. end
  19.  
  20.  
  21.  
  22. bin = script.Parent
  23.  
  24.  
  25.  
  26. function prop(part, parent, collide, tran, ref, x, y, z, color, anchor)
  27.  
  28. part.Parent = parent
  29.  
  30. part.formFactor = 0
  31.  
  32. part.CanCollide = collide
  33.  
  34. part.Transparency = tran
  35.  
  36. part.Reflectance = ref
  37.  
  38. part.Size = Vector3.new(x,y,z)
  39.  
  40. part.BrickColor = BrickColor.new(color)
  41.  
  42. part.TopSurface = 0
  43.  
  44. part.BottomSurface = 0
  45.  
  46. part.Anchored = anchor
  47.  
  48. part:BreakJoints()
  49.  
  50. end
  51.  
  52.  
  53.  
  54. function weld(w, p, p0, p1, a, b, c, x, y, z)
  55.  
  56. w.Parent = p
  57.  
  58. w.Part0 = p0
  59.  
  60. w.Part1 = p1
  61.  
  62. w.C1 = CFrame.fromEulerAnglesXYZ(a,b,c) * CFrame.new(x,y,z)
  63.  
  64. end
  65.  
  66.  
  67.  
  68. function mesh(mesh, parent, x, y, z, type)
  69.  
  70. mesh.Parent = parent
  71.  
  72. mesh.Scale = Vector3.new(x, y, z)
  73.  
  74. mesh.MeshType = type
  75.  
  76. end
  77.  
  78.  
  79.  
  80. function placeturret(mainplace)
  81.  
  82. local turret = Instance.new("Model",workspace)
  83.  
  84. turret.Name = "Turret"
  85.  
  86.  
  87.  
  88. local main = Instance.new("Part")
  89.  
  90. prop(main, turret, true, 0, 0, 3, 1, 3, "Dark grey", true)
  91.  
  92. main.CFrame = CFrame.new(mainplace)
  93.  
  94. mainmesh = Instance.new("CylinderMesh",main)
  95.  
  96.  
  97.  
  98. local neck = Instance.new("Part")
  99.  
  100. prop(neck,turret,true,0,0,1,2,1,"Dark grey", true)
  101.  
  102. neck.CFrame = CFrame.new(mainplace) * CFrame.new(0,1.1,0)
  103.  
  104. neckmesh = Instance.new("CylinderMesh",neck)
  105.  
  106. neckmesh.Scale = Vector3.new(1,1.5,1)
  107.  
  108.  
  109.  
  110. local move = Instance.new("Part")
  111.  
  112. prop(move, turret, false, 0, 0, 1, 1, 5,"Dark grey", false)
  113.  
  114. move.CFrame = CFrame.new(mainplace) * CFrame.new(0,3,0)
  115.  
  116.  
  117.  
  118. local bg = Instance.new("BodyGyro")
  119.  
  120. bg.Parent = move
  121.  
  122. bg.maxTorque = Vector3.new(1e+008,1e+008,1e+008)
  123.  
  124.  
  125.  
  126. local bp = Instance.new("BodyPosition",move)
  127.  
  128. bp.maxForce = Vector3.new(1e+008,1e+008,1e+008)
  129.  
  130. bp.position = bp.Parent.Position
  131.  
  132.  
  133.  
  134. local gunner = Instance.new("Part")
  135.  
  136. gunner.FrontSurface = "Hinge"
  137.  
  138. prop(gunner,turret,true,0,0,1,1,1,"Dark grey",false)
  139.  
  140. gunner.CFrame = CFrame.new(mainplace) * CFrame.new(0,3,2.5)
  141.  
  142.  
  143.  
  144. local gunweld = Instance.new("Weld")
  145.  
  146. weld(gunweld,move,move,gunner,0,0,0,0,0,2.5)
  147.  
  148.  
  149.  
  150. local sound = Instance.new("Sound",gunner)
  151.  
  152. sound.Volume = 0.8
  153.  
  154. sound.Pitch = 4
  155.  
  156. sound.SoundId = "http://www.roblox.com/asset/?id=2760979"
  157.  
  158.  
  159.  
  160. function find(pos)
  161.  
  162. local list = game.Workspace:children()
  163.  
  164. local torso = nil
  165.  
  166. local dist = 40
  167.  
  168. local temp = nil
  169.  
  170. local human = nil
  171.  
  172. local temp2 = nil
  173.  
  174. for x = 1, #list do
  175.  
  176. temp2 = list[x]
  177.  
  178. if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  179.  
  180. temp = temp2:findFirstChild("Torso")
  181.  
  182. human = temp2:findFirstChild("Humanoid")
  183.  
  184. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  185.  
  186. if (temp.Position - pos).magnitude < dist then
  187.  
  188. torso = temp
  189.  
  190. dist = (temp.Position - pos).magnitude
  191.  
  192. end
  193.  
  194. end
  195.  
  196. end
  197.  
  198. end
  199.  
  200. return torso
  201.  
  202. end
  203.  
  204.  
  205.  
  206. coroutine.resume(coroutine.create(function()
  207.  
  208. while true do
  209.  
  210. if gunner.Parent ~= nil then
  211.  
  212. wait(0.1)
  213.  
  214. local target = find(gunner.Position)
  215.  
  216. if target ~= nil then
  217.  
  218. bg.cframe = CFrame.new(move.Position, target.Position)
  219.  
  220. local meh = math.random(1,6)
  221.  
  222. if meh == 1 then
  223.  
  224. local bulls = {}
  225.  
  226. local dis = (gunner.Position - target.Position).magnitude
  227.  
  228. local bullet = Instance.new("Part")
  229.  
  230. prop(bullet,workspace,false,0,0,1,1,1,"Bright yellow",true)
  231.  
  232. bullet.CFrame = CFrame.new(gunner.Position, target.Position) * CFrame.new(0,0,-dis/2)
  233.  
  234. local meu = Instance.new("SpecialMesh")
  235.  
  236. mesh(meu,bullet,0.23,0.23,dis,"Brick")
  237.  
  238. local huo = target.Parent:findFirstChild("Humanoid")
  239.  
  240. huo:TakeDamage(math.random(huo.MaxHealth/34,huo.MaxHealth/8))
  241.  
  242. local randompitch = math.random(500,1200)/1000
  243.  
  244. sound.Pitch = randompitch
  245.  
  246. sound:play()
  247.  
  248. table.insert(bulls,bullet)
  249.  
  250. for i=1, math.random(3,6) do
  251.  
  252. local msi = math.random(8,23)/10
  253.  
  254. local th = Instance.new("Part")
  255.  
  256. prop(th,workspace,false,0,0,1,1,1,"Bright yellow",true)
  257.  
  258. th.CFrame = CFrame.new(gunner.Position,target.Position) * CFrame.new(0,0,-dis)
  259.  
  260. th.CFrame = th.CFrame * CFrame.Angles(math.random(-100,100),math.random(-100,100),math.random(-100,100))
  261.  
  262. th.CFrame = th.CFrame * CFrame.new(0,0,-msi/2)
  263.  
  264. thme = Instance.new("SpecialMesh")
  265.  
  266. mesh(thme,th,0.13,0.13,msi, "Brick")
  267.  
  268. table.insert(bulls,th)
  269.  
  270. for duh=1, math.random(2,5) do
  271.  
  272. local bag = math.random(5,18)/10
  273.  
  274. local bah = Instance.new("Part")
  275.  
  276. prop(bah,workspace,false,0,0,1,1,1,"Bright yellow",true)
  277.  
  278. bah.CFrame = CFrame.new(th.Position) * CFrame.new(0,0,msi/2)
  279.  
  280. bah.CFrame = bah.CFrame * CFrame.Angles(math.random(-100,100),math.random(-100,100),math.random(-100,100))
  281.  
  282. bah.CFrame = bah.CFrame * CFrame.new(0,0,-bag/2)
  283.  
  284. bahme = Instance.new("SpecialMesh")
  285.  
  286. mesh(bahme,bah,0.02,0.02,bag, "Brick")
  287.  
  288. table.insert(bulls,bah)
  289.  
  290. end
  291.  
  292. end
  293.  
  294. coroutine.resume(coroutine.create(function()
  295.  
  296. for i=1, #bulls do
  297.  
  298. coroutine.resume(coroutine.create(function()
  299.  
  300. wait(0.1)
  301.  
  302. for k=0, 1, 0.25 do
  303.  
  304. wait()
  305.  
  306. bulls[i].Transparency = k
  307.  
  308. end
  309.  
  310. bulls[i]:remove()
  311.  
  312. end))
  313.  
  314. end
  315.  
  316. end))
  317.  
  318. end
  319.  
  320. end
  321.  
  322. end
  323.  
  324. end
  325.  
  326. end))
  327.  
  328. end
  329.  
  330.  
  331.  
  332. bin.Selected:connect(function(mouse)
  333.  
  334. mouse.Button1Down:connect(function()
  335.  
  336. placeturret(mouse.Hit.p)
  337.  
  338. end)
  339.  
  340. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement