Advertisement
TheUnknownDiscord

turret

Dec 5th, 2021 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local rayblacklist = {}
  2. workspace.DescendantAdded:Connect(function(WHAT) -- thank rufus
  3. if WHAT:IsA("Accessory") or WHAT:IsA("Hat") then
  4. table.insert(rayblacklist, WHAT)
  5. elseif WHAT:IsA("BasePart") and not WHAT.CanCollide then
  6. table.insert(rayblacklist, WHAT)
  7. end
  8. end)
  9. for i,v in pairs(owner.Character:GetDescendants()) do
  10. pcall(function()
  11. table.insert(rayblacklist, v)
  12. end)
  13. end
  14. off = false
  15. owner.Chatted:Connect(function(msg)
  16. if string.lower(msg) == "deactivate sentry" then
  17. off = true
  18. elseif string.lower(msg) == "activate sentry" then
  19. off = false
  20. end
  21. end)
  22. local part1 = Instance.new("Part", script)
  23. local part2 = Instance.new("Part", part1)
  24. part1.Size = Vector3.new(1.25,1,1.75)
  25. part2.Size = Vector3.new(1,2,2)
  26. part2.Shape = "Cylinder"
  27. part2.Color = Color3.fromRGB(199, 20, 0)
  28. part1.Color = Color3.fromRGB(199, 20, 0)
  29. part2.Material = "SmoothPlastic"
  30. part1.Material = "SmoothPlastic"
  31. local part3 = Instance.new("Part", part1)
  32. part3.Size = Vector3.new(1.0625,1.65,1.65)
  33. part3.Shape = "Cylinder"
  34. part3.Color = Color3.fromRGB(43, 43, 43)
  35. part3.Material = "SmoothPlastic"
  36. local part4 = Instance.new("Part", part1)
  37. part4.Size = Vector3.new(1.255,1.005,0.95)
  38. part4.Color = Color3.fromRGB(43, 43, 43)
  39. part4.Material = "SmoothPlastic"
  40. local part5 = Instance.new("Part", part1)
  41. part5.Size = Vector3.new(0.01,2.01,2.01)
  42. part5.Shape = "Cylinder"
  43. part5.Color = Color3.fromRGB(43, 43, 43)
  44. part5.Material = "SmoothPlastic"
  45. local part6 = Instance.new("Part", part1)
  46. part6.Size = Vector3.new(0.01,2.01,2.01)
  47. part6.Shape = "Cylinder"
  48. part6.Color = Color3.fromRGB(43, 43, 43)
  49. part6.Material = "SmoothPlastic"
  50. local part7 = Instance.new("Part", part1)
  51. part7.Size = Vector3.new(1.251,0.01,1.4)
  52. part7.Color = Color3.fromRGB(43, 43, 43)
  53. part7.Material = "SmoothPlastic"
  54. local part8 = Instance.new("Part", part1)
  55. part8.Size = Vector3.new(1.251,0.01,1.4)
  56. part8.Color = Color3.fromRGB(43, 43, 43)
  57. part8.Material = "SmoothPlastic"
  58. local part9 = Instance.new("Part", part1)
  59. part9.Size = Vector3.new(0.75,0.3,0.3)
  60. part9.Shape = "Cylinder"
  61. part9.Color = Color3.fromRGB(43, 43, 43)
  62. part9.Material = "SmoothPlastic"
  63. local part10 = Instance.new("Part", part1)
  64. part10.Size = Vector3.new(0.1,0.4,0.4)
  65. part10.Shape = "Cylinder"
  66. part10.Color = Color3.fromRGB(43, 43, 43)
  67. part10.Material = "SmoothPlastic"
  68. local part11 = Instance.new("Part", part1)
  69. part11.Size = Vector3.new(0.23,0.2,0.2)
  70. part11.Shape = "Cylinder"
  71. part11.Color = Color3.fromRGB(43, 43, 43)
  72. part11.Material = "SmoothPlastic"
  73. local part12 = Instance.new("Part", part1)
  74. part12.Size = Vector3.new(0.1,0.1,0.1)
  75. part12.Shape = "Cylinder"
  76. part12.Color = Color3.fromRGB(43, 43, 43)
  77. part12.Material = "SmoothPlastic"
  78. local part13 = Instance.new("Part", part1)
  79. part13.Size = Vector3.new(0.125,0.075,0.075)
  80. part13.Shape = "Cylinder"
  81. part13.Color = Color3.fromRGB(199, 20, 0)
  82. part13.Material = "Neon"
  83. local part14 = Instance.new("Part", part1)
  84. part14.Size = Vector3.new(0.13,0.08,0.08)
  85. part14.Shape = "Cylinder"
  86. part14.Color = Color3.fromRGB(199, 20, 0)
  87. part14.Transparency = 0.4
  88. part14.Material = "Glass"
  89. local part15 = Instance.new("Part", part1)
  90. part15.Size = Vector3.new(1.5,0.35,0.35)
  91. part15.Shape = "Cylinder"
  92. part15.Color = Color3.fromRGB(43, 43, 43)
  93. part15.Material = "SmoothPlastic"
  94. part15.Anchored = true
  95. local part16 = Instance.new("Part", part1)
  96. part16.Size = Vector3.new(0.125,0.45,0.45)
  97. part16.Shape = "Cylinder"
  98. part16.Color = Color3.fromRGB(43, 43, 43)
  99. part16.Material = "SmoothPlastic"
  100. part16.Anchored = true
  101. local part20 = Instance.new("Part", part1)
  102. part20.Size = Vector3.new(2,0.35,0.35)
  103. part20.Shape = "Cylinder"
  104. part20.Color = Color3.fromRGB(43, 43, 43)
  105. part20.Material = "SmoothPlastic"
  106. local part21 = Instance.new("Part", part1)
  107. part21.Size = Vector3.new(2,0.35,0.35)
  108. part21.Shape = "Cylinder"
  109. part21.Color = Color3.fromRGB(43, 43, 43)
  110. part21.Material = "SmoothPlastic"
  111. local part22 = Instance.new("Part", part1)
  112. part22.Size = Vector3.new(2,0.35,0.35)
  113. part22.Shape = "Cylinder"
  114. part22.Color = Color3.fromRGB(43, 43, 43)
  115. part22.Material = "SmoothPlastic"
  116. local part17 = Instance.new("Part", part1)
  117. part17.Size = Vector3.new(1.65,0.125,1)
  118. part17.Color = Color3.fromRGB(43, 43, 43)
  119. part17.Material = "SmoothPlastic"
  120. local part18 = Instance.new("Part", part17)
  121. part18.Size = Vector3.new(0.125,1.5,1)
  122. part18.Color = Color3.fromRGB(43, 43, 43)
  123. part18.Material = "SmoothPlastic"
  124. local part19 = Instance.new("Part", part17)
  125. part19.Size = Vector3.new(0.125,1.5,1)
  126. part19.Color = Color3.fromRGB(43, 43, 43)
  127. part19.Material = "SmoothPlastic"
  128. part19.Massless = true
  129. part18.Massless = true
  130. part17.Massless = true
  131. part16.Massless = true
  132. part15.Massless = true
  133. part14.Massless = true
  134. part13.Massless = true
  135. part12.Massless = true
  136. part11.Massless = true
  137. part10.Massless = true
  138. part9.Massless = true
  139. part8.Massless = true
  140. part7.Massless = true
  141. part6.Massless = true
  142. part5.Massless = true
  143. part3.Massless = true
  144. part2.Massless = true
  145. part1.Massless = true
  146. for i,v in pairs(script:GetDescendants()) do
  147. pcall(function()
  148. table.insert(rayblacklist, v)
  149. end)
  150. end
  151. local weld = Instance.new("Weld", part1)
  152. weld.Part0 = part2
  153. weld.Part1 = part1
  154. weld.C0 = CFrame.Angles(0,0,math.rad(90)) * CFrame.new(0,0,-1.35)
  155. local weld2 = Instance.new("Weld", part1)
  156. weld2.Part0 = part3
  157. weld2.Part1 = part1
  158. weld2.C0 = CFrame.Angles(0,0,math.rad(90)) * CFrame.new(0,0,-1.35)
  159. local weld3 = Instance.new("Weld", part1)
  160. weld3.Part0 = part4
  161. weld3.Part1 = part1
  162. weld3.C0 = CFrame.new(0,0,0.39)
  163. local weld4 = Instance.new("Weld", part1)
  164. weld4.Part0 = part5
  165. weld4.Part1 = part1
  166. weld4.C0 = CFrame.Angles(0,0,math.rad(90)) * CFrame.new(0,0.4,-1.35)
  167. local weld5 = Instance.new("Weld", part1)
  168. weld5.Part0 = part6
  169. weld5.Part1 = part1
  170. weld5.C0 = CFrame.Angles(0,0,math.rad(90)) * CFrame.new(0,-0.4,-1.35)
  171. local weld6 = Instance.new("Weld", part1)
  172. weld6.Part0 = part7
  173. weld6.Part1 = part1
  174. weld6.C0 = CFrame.new(0,-0.4,0)
  175. local weld7 = Instance.new("Weld", part1)
  176. weld7.Part0 = part8
  177. weld7.Part1 = part1
  178. weld7.C0 = CFrame.new(0,0.4,0)
  179. local weld8 = Instance.new("Weld", part1)
  180. weld8.Part0 = part9
  181. weld8.Part1 = part1
  182. weld8.C0 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(0,0,1)
  183. local weld9 = Instance.new("Weld", part1)
  184. weld9.Part0 = part10
  185. weld9.Part1 = part1
  186. weld9.C0 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(0,0,0.85)
  187. local weld10 = Instance.new("Weld", part1)
  188. weld10.Part0 = part11
  189. weld10.Part1 = part1
  190. weld10.C0 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(-0.375,0.3,0.85)
  191. local weld11 = Instance.new("Weld", part1)
  192. weld11.Part0 = part12
  193. weld11.Part1 = part1
  194. weld11.C0 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(-0.4,0.05,0.85)
  195. local weld12 = Instance.new("Weld", part1)
  196. weld12.Part0 = part13
  197. weld12.Part1 = part1
  198. weld12.C0 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(-0.4,0.05,0.95)
  199. local weld13 = Instance.new("Weld", part1)
  200. weld13.Part0 = part14
  201. weld13.Part1 = part1
  202. weld13.C0 = CFrame.Angles(0,math.rad(90),0) * CFrame.new(-0.4,0.05,0.95)
  203. local weld14 = Instance.new("Weld", part17)
  204. weld14.Part0 = part18
  205. weld14.Part1 = part17
  206. weld14.C0 = CFrame.new(-0.8,-0.7,0)
  207. local weld15 = Instance.new("Weld", part17)
  208. weld15.Part0 = part19
  209. weld15.Part1 = part17
  210. weld15.C0 = CFrame.new(0.8,-0.7,0)
  211. local weld16 = Instance.new("Weld", part15)
  212. weld16.Part0 = part20
  213. weld16.Part1 = part15
  214. weld16.C0 = CFrame.Angles(0,math.rad(22.5),math.rad(45)) * CFrame.new(0.75,-0.75,0.5)
  215. local weld17 = Instance.new("Weld", part15)
  216. weld17.Part0 = part21
  217. weld17.Part1 = part15
  218. weld17.C0 = CFrame.Angles(0,math.rad(22.5),math.rad(-45)) * CFrame.new(0.75,0.75,0.5)
  219. local weld18 = Instance.new("Weld", part15)
  220. weld18.Part0 = part22
  221. weld18.Part1 = part15
  222. weld18.C0 = CFrame.Angles(0,math.rad(-45),0) * CFrame.new(0.75,0,-0.75)
  223. part1.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(0,0.5,-5)
  224. part17.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(0,-0.35,-5.25)
  225. part17.CanCollide = false
  226. part18.CanCollide = false
  227. part19.CanCollide = false
  228. local alert = Instance.new("Sound", part4)
  229. alert.Volume = 2
  230. alert.SoundId = "rbxassetid://8182830328"
  231. local searching = Instance.new("Sound", part4)
  232. searching.Volume = 2
  233. searching.Looped = true
  234. searching.SoundId = "rbxassetid://8191866994"
  235. local shooting = Instance.new("Sound", part4)
  236. shooting.Volume = 2
  237. shooting.Looped = true
  238. shooting.SoundId = "rbxassetid://7615746395"
  239. local shooting2 = Instance.new("Sound", part4)
  240. shooting2.Volume = 2
  241. shooting2.Looped = true
  242. shooting2.SoundId = "rbxassetid://7615746395"
  243. part15.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.Angles(0,0,math.rad(90)) * CFrame.new(-1.125,0,-5.25)
  244. part16.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.Angles(0,0,math.rad(90)) * CFrame.new(-0.5,0,-5.25)
  245. alignposition = Instance.new("HingeConstraint")
  246. alignposition.Parent = part17
  247. alignposition.ActuatorType = Enum.ActuatorType.None
  248. local at0 = Instance.new("Attachment")
  249. at0.Parent = part17
  250. at0.WorldCFrame = part4.CFrame
  251. local at1 = Instance.new("Attachment")
  252. at1.Parent = part4
  253. at1.WorldCFrame = at1.Parent.CFrame
  254. alignposition.Attachment0 = at0
  255. alignposition.Attachment1 = at1
  256. alignposition2 = Instance.new("HingeConstraint")
  257. alignposition2.Parent = part16
  258. alignposition2.ActuatorType = Enum.ActuatorType.None
  259. local at2 = Instance.new("Attachment")
  260. at2.Parent = part16
  261. at2.WorldCFrame = part17.CFrame * CFrame.Angles(0,0,math.rad(90))
  262. local at3 = Instance.new("Attachment")
  263. at3.Parent = part17
  264. at3.WorldCFrame = at3.Parent.CFrame * CFrame.Angles(0,0,math.rad(90))
  265. alignposition2.Attachment0 = at2
  266. alignposition2.Attachment1 = at3
  267. bg = Instance.new("BodyGyro",part4)
  268. bg.P = 10000
  269. bg.D = 500
  270. bg.MaxTorque = Vector3.new(math.huge,0,0)
  271. bg2 = Instance.new("BodyGyro",part17)
  272. bg2.P = 10000
  273. bg2.D = 500
  274. bg2.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
  275. bg.CFrame = part4.CFrame
  276. bg2.CFrame = part17.CFrame
  277. TweenService = game:GetService("TweenService")
  278. spininfo = TweenInfo.new(0.75,Enum.EasingStyle.Linear)
  279. Spin1 = TweenService:Create(bg2,spininfo,{CFrame = bg2.CFrame * CFrame.Angles(0,math.rad(85),0)})
  280. Spin2 = TweenService:Create(bg2,spininfo,{CFrame = bg2.CFrame * CFrame.Angles(0,math.rad(45),0)})
  281. Spin5 = TweenService:Create(bg2,spininfo,{CFrame = bg2.CFrame * CFrame.Angles(0,math.rad(0),0)})
  282. Spin3 = TweenService:Create(bg2,spininfo,{CFrame = bg2.CFrame * CFrame.Angles(0,math.rad(-85),0)})
  283. Spin4 = TweenService:Create(bg2,spininfo,{CFrame = bg2.CFrame * CFrame.Angles(0,math.rad(-45),0)})
  284. Spin6 = TweenService:Create(bg,spininfo,{CFrame = bg.CFrame})
  285. damaging = false
  286. candamage = true
  287. nowall = true
  288. function wallcheck(who,mod)
  289. local iforgor = {}
  290. local raycastParams = RaycastParams.new()
  291. raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
  292. raycastParams.FilterDescendantsInstances = {rayblacklist,who,mod}
  293. raycastParams.IgnoreWater = true
  294. local result = workspace:Raycast(part.Position, CFrame.new(part4.Position,who.Position).lookVector * (part4.Position - who.Position).Magnitude, raycastParams)
  295. if result then
  296. table.insert(iforgor,mod)
  297. end
  298. return iforgor
  299. end
  300. function move(target)
  301. local dir = (target.Position - part4.Position).unit
  302. local spawnPos = part4.Position
  303. local pos = spawnPos + (dir * 1)
  304. local cf = CFrame.new(pos, pos + dir * 50)
  305. coroutine.wrap(function()
  306. pcall(function()
  307. if not off and candamage then
  308. candamage = false
  309. local hum = target.Parent:findFirstChild("Humanoid")
  310. hum.Health = hum.Health - 15
  311. pcall(function()
  312. local Flame3 = Instance.new("SpawnLocation", script)
  313. Flame3.Size = Vector3.new(0.5,0.5,0.5)
  314. Flame3.Neutral = false
  315. Flame3.Enabled = false
  316. Flame3.CFrame = part4.CFrame * CFrame.new(0,0,-1.25) * CFrame.Angles(math.rad(math.random(-360,360)),math.rad(math.random(-360,360)),math.rad(math.random(-360,360)))
  317. Flame3.CanCollide = false
  318. Flame3.Color = Color3.fromRGB(255, 50, 50)
  319. Flame3.Material = "Neon"
  320. Flame3.Anchored = true
  321. Flame3.Name = "Flameslol"
  322. game:GetService("Debris"):AddItem(Flame3,0.5)
  323. local timeToFade6 = 0.5
  324. local object6 = Flame3
  325. local tweenInfo6 = TweenInfo.new(timeToFade6)
  326. local goal9 = {}
  327. goal9.Color = Color3.fromRGB(255, 155, 0)
  328. local tween9 = tweenService:Create(object6, tweenInfo6, goal9)
  329. tween9:Play()
  330. local flash = Instance.new("PointLight", Flame3)
  331. flash.Brightness = 3
  332. game:GetService("Debris"):AddItem(flash,0.5)
  333. for i = 1, 4 do
  334. wait(0.0125)
  335. Flame3.CFrame = Flame3.CFrame * CFrame.Angles(math.rad(math.random(-360,360)),math.rad(math.random(-360,360)),math.rad(math.random(-360,360)))
  336. end
  337. end)
  338. wait(0.5)
  339. candamage = true
  340. end
  341. end)
  342. end)()
  343. end
  344. function findNearestTorso(pos,forgort)
  345. pcall(function()
  346. local list = workspace:GetChildren()
  347. local torso = nil
  348. local dist = 50
  349. local temp = nil
  350. local human = nil
  351. local temp2 = nil
  352. for x = 1, #list do
  353. temp2 = list[x]
  354. if (temp2.className == "Model") and (temp2 ~= owner.Character) and not table.find(forgort,temp2) then
  355. temp = temp2:findFirstChild("Head")
  356. human = temp2:findFirstChild("Humanoid")
  357. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  358. if (temp.Position - pos).magnitude < dist then
  359. torso = temp
  360. dist = (temp.Position - pos).magnitude
  361. end
  362. end
  363. end
  364. end
  365. return torso,temp2
  366. end)
  367. end
  368. db = false
  369. db2 = false
  370. function targetlocked()
  371. coroutine.wrap(function()
  372. if not db then
  373. db = true
  374. searching:Stop()
  375. alert:Play()
  376. alert.Ended:Wait()
  377. shooting:Play()
  378. wait(1.5)
  379. shooting2:Play()
  380. end
  381. end)()
  382. end
  383. local nowall = true
  384. function targetnil()
  385. coroutine.wrap(function()
  386. if not db2 then
  387. db2 = true
  388. searching:Play()
  389. shooting:Stop()
  390. shooting2:Stop()
  391. end
  392. end)()
  393. end
  394. coroutine.wrap(function()
  395. while true do
  396. if not off then
  397. local torso,temp2 = findNearestTorso(part4.Position)
  398. if torso~=nil and temp2 ~= nil then
  399. local iforgor = wallcheck(torso,temp2)
  400. local torso,temp2 = findNearestTorso(part4.Position,iforgor)
  401. if torso~=nil then
  402. move(torso)
  403. nowall = true
  404. targetlocked()
  405. db2 = false
  406. else
  407. nowall = false
  408. db = false
  409. targetnil()
  410. end
  411. end
  412. task.wait()
  413. end
  414. end
  415. end)()
  416. cycled = false
  417. wait()
  418. while true do
  419. task.wait()
  420. if not cycled then
  421. cycled = true
  422. Spin6:Play()
  423. if db2 then
  424. coroutine.wrap(function()
  425. Spin2:Play()
  426. wait(0.75)
  427. Spin1:Play()
  428. wait(0.75)
  429. Spin2:Play()
  430. wait(0.75)
  431. Spin5:Play()
  432. wait(0.75)
  433. Spin4:Play()
  434. wait(0.75)
  435. Spin3:Play()
  436. wait(0.75)
  437. Spin4:Play()
  438. wait(0.75)
  439. Spin5:Play()
  440. wait(0.75)
  441. cycled = false
  442. end)()
  443. elseif not nowall then
  444. Spin1:Cancel()
  445. Spin2:Cancel()
  446. Spin3:Cancel()
  447. Spin4:Cancel()
  448. Spin5:Cancel()
  449. Spin6:Cancel()
  450. cycled = false
  451. elseif not db2 then
  452. Spin1:Cancel()
  453. Spin2:Cancel()
  454. Spin3:Cancel()
  455. Spin4:Cancel()
  456. Spin5:Cancel()
  457. Spin6:Cancel()
  458. cycled = false
  459. end
  460. end
  461. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement