sawgamer1

Untitled

Jan 5th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.62 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4. local env = getfenv(func)
  5. local newenv = setmetatable({},{
  6. __index = function(self,k)
  7. if k=="script" then
  8. return var
  9. else
  10. return env[k]
  11. end
  12. end,
  13. })
  14. setfenv(func,newenv)
  15. return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Model0 = Instance.new("Model")
  20. Script1 = Instance.new("Script")
  21. Script2 = Instance.new("Script")
  22. Model3 = Instance.new("Model")
  23. Part4 = Instance.new("Part")
  24. Part5 = Instance.new("Part")
  25. Part6 = Instance.new("Part")
  26. Script7 = Instance.new("Script")
  27. Part8 = Instance.new("Part")
  28. Part9 = Instance.new("Part")
  29. Part10 = Instance.new("Part")
  30. Part11 = Instance.new("Part")
  31. Part12 = Instance.new("Part")
  32. Part13 = Instance.new("Part")
  33. SpecialMesh14 = Instance.new("SpecialMesh")
  34. Decal15 = Instance.new("Decal")
  35. Script16 = Instance.new("Script")
  36. Model0.Parent = mas
  37. Script1.Name = "Tutorial"
  38. Script1.Parent = Model0
  39. table.insert(cors,sandbox(Script1,function()
  40. -- Hello everyone, ImaBoss838 here. This is a small read me/tutorial on how to set up Redditor's pathfinding zombie ai.
  41.  
  42. -- Lets start off with the basics:
  43.  
  44. -- *You can edit the detection distance on the AI in the controller script, i've highlighted the line.
  45. -- *The "Spawner" script is just kind of a duplicator script, it duplicates the zombie and respawns it.
  46. -- *Inside the "Spawner" script there is the model, aka, the zombie AI. You can copy it and paste it as you like.
  47. -- *Inside the Zombie AI there is a script, edit the stats there. (The ones I tell you that you can edit, its marked in the script)
  48.  
  49. -- Now, with that out of the way, its not really much else to say, right now you cant tweak as much on this AI, unless you know what you're doing.
  50. -- Happy zombie slaying!
  51. end))
  52. Script2.Name = "Spawner"
  53. Script2.Parent = Model0
  54. table.insert(cors,sandbox(Script2,function()
  55. local model = script:GetChildren()[1]:clone()
  56.  
  57. script.ChildRemoved:connect(function()
  58. for i = 1, 25 - #script:GetChildren() do
  59. local m = model:clone()
  60. m.Parent = script
  61. m:MoveTo(Vector3.new(math.random() * 200-100, 5, math.random() * 200-100))
  62. end
  63. end)
  64. script:GetChildren()[1]:Destroy()
  65. end))
  66. Model3.Name = "Zombie A.I"
  67. Model3.Parent = Script2
  68. Part4.Name = "Right Leg"
  69. Part4.Parent = Model3
  70. Part4.CFrame = CFrame.new(-12.199996, 1.90001094, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  71. Part4.Position = Vector3.new(-12.199996, 1.90001094, -16.1000061)
  72. Part4.Color = Color3.new(0, 0.560784, 0.611765)
  73. Part4.Transparency = 1
  74. Part4.Size = Vector3.new(1, 1, 1)
  75. Part4.Anchored = true
  76. Part4.BottomSurface = Enum.SurfaceType.Smooth
  77. Part4.BrickColor = BrickColor.new("Bright bluish green")
  78. Part4.Locked = true
  79. Part4.TopSurface = Enum.SurfaceType.Smooth
  80. Part4.brickColor = BrickColor.new("Bright bluish green")
  81. Part4.FormFactor = Enum.FormFactor.Custom
  82. Part4.formFactor = Enum.FormFactor.Custom
  83. Part5.Name = "Torso"
  84. Part5.Parent = Model3
  85. Part5.CFrame = CFrame.new(-12.199996, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  86. Part5.Position = Vector3.new(-12.199996, 3.00001192, -16.1000061)
  87. Part5.Color = Color3.new(0.388235, 0.372549, 0.384314)
  88. Part5.Transparency = 1
  89. Part5.Size = Vector3.new(2, 2, 2)
  90. Part5.Anchored = true
  91. Part5.BottomSurface = Enum.SurfaceType.Smooth
  92. Part5.BrickColor = BrickColor.new("Dark stone grey")
  93. Part5.Friction = 0
  94. Part5.Locked = true
  95. Part5.TopSurface = Enum.SurfaceType.Smooth
  96. Part5.brickColor = BrickColor.new("Dark stone grey")
  97. Part5.FormFactor = Enum.FormFactor.Symmetric
  98. Part5.formFactor = Enum.FormFactor.Symmetric
  99. Part5.Shape = Enum.PartType.Ball
  100. Part6.Name = "Head"
  101. Part6.Parent = Model3
  102. Part6.CFrame = CFrame.new(-12.199996, 4.50000381, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  103. Part6.Position = Vector3.new(-12.199996, 4.50000381, -16.1000061)
  104. Part6.Color = Color3.new(0, 0.560784, 0.611765)
  105. Part6.Transparency = 1
  106. Part6.Size = Vector3.new(1, 1, 1)
  107. Part6.Anchored = true
  108. Part6.BottomSurface = Enum.SurfaceType.Smooth
  109. Part6.BrickColor = BrickColor.new("Bright bluish green")
  110. Part6.FrontSurface = Enum.SurfaceType.Hinge
  111. Part6.Locked = true
  112. Part6.TopSurface = Enum.SurfaceType.Smooth
  113. Part6.brickColor = BrickColor.new("Bright bluish green")
  114. Part6.FormFactor = Enum.FormFactor.Custom
  115. Part6.formFactor = Enum.FormFactor.Custom
  116. Script7.Parent = Model3
  117. table.insert(cors,sandbox(Script7,function()
  118. local ai = {}
  119. ai.Model = script.Parent
  120.  
  121. -- The zombies memory. (You can edit these stats)
  122. local goalPos
  123. local lastAttack = time()
  124. local attackTime = .3
  125. local atkDamage = 5
  126. local goalHumanoid
  127. local running
  128. local running2
  129. local crawling
  130. local limp = {}
  131. for i = 1, 10 do
  132. limp[i] = (math.random() * 2) - 1
  133. end
  134.  
  135. -- Global functions. (I wouldnt mess with this..)
  136. ai.Move = function(loc, mustSee, humanoid)
  137. goalHumanoid = humanoid
  138. if goalPos then
  139. goalPos = loc
  140. else
  141. goalPos = loc
  142. Spawn(function()
  143. ai.State = "Tracking"
  144. local lastGoal
  145. local lastTime = time()
  146. while goalPos and ai.Humanoid do
  147. local gp = goalPos
  148. if pcall(function() return goalPos.X end) then
  149. elseif goalPos:IsA("BasePart") then
  150. gp = (ai.canSee(goalPos) or not mustSee) and goalPos.Position or nil
  151. lastTime = time()
  152. elseif goalPos:IsA("Model") then
  153. gp = nil
  154. for _, bodyPart in pairs(goalPos:GetChildren()) do
  155. if bodyPart:IsA("BasePart") and (ai.canSee(bodyPart) or not mustSee) then
  156. gp = goalPos:GetModelCFrame().p
  157. lastTime = time()
  158. break
  159. end
  160. end
  161. end
  162. lastGoal = gp and humanoid and gp + (gp - ai.Model.Torso.Position).unit * 10 or gp or lastGoal or ai.Model.Torso.Position
  163. if (goalHumanoid and goalHumanoid.Health <= 0) or (not goalHumanoid and (ai.Model.Torso.Position - lastGoal).magnitude < 3) or time() - lastTime > 3 then
  164. goalPos = nil
  165. else
  166. ai.Humanoid.Jump = objAhead(lastGoal)
  167. ai.Humanoid:MoveTo(lastGoal, workspace.Terrain)
  168. if goalHumanoid and ((ai.Model.Torso.Position - goalPos:GetModelCFrame().p) * Vector3.new(1,.5,1)).magnitude < 3 and time() - lastAttack > attackTime then
  169. attack(goalHumanoid)
  170. end
  171. end
  172. wait(.1)
  173. end
  174. if ai then
  175. ai.State = "Idle"
  176. end
  177. end)
  178. end
  179. end
  180.  
  181.  
  182.  
  183.  
  184. --local functions
  185. function weld(a, b, c0, c1)
  186. local w = Instance.new("Weld", a)
  187. w.Part0 = a
  188. w.Part1 = b
  189. if c0 then w.C0 = c0 end
  190. if c1 then w.C1 = c1 end
  191. return w
  192. end
  193.  
  194. function setHeight(n)
  195. if ai.Model:findFirstChild("Right Leg") then
  196. ai.Model["Right Leg"]:BreakJoints()
  197. ai.Model["Right Leg"].Size = ai.Model["Right Leg"].Size * Vector3.new(1,0,1) + Vector3.new(0, math.max(0.2, n or 0),0)
  198. weld(ai.Model.Torso, ai.Model["Right Leg"], CFrame.new(0, -n + ai.Model["Right Leg"].Size.Y/2 - ai.Model.Torso.Size.Y/2,0))
  199. end
  200. if m and ai.Model:findFirstChild("Head") then
  201. ai.Model.Head:BreakJoints()
  202. weld(ai.Model.Torso, ai.Model.Head, CFrame.new(0, m - ai.Model.Head.Size.Y/2 + ai.Model.Torso.Size.Y/2,0))
  203. end
  204. end
  205.  
  206. function objAhead(loc)
  207. if not _G.AntiJumpCache then
  208. _G.AntiJumpCache = {}
  209. end
  210. local ray = Ray.new(ai.Model.Torso.Position, ((loc - ai.Model.Torso.Position) * Vector3.new(1,0,1)).unit * 5)
  211. local obj, pos = workspace:FindPartOnRayWithIgnoreList(ray, _G.AntiJumpCache)
  212. if obj then
  213. if not obj.CanCollide then
  214. table.insert(_G.AntiJumpCache, obj)
  215. elseif obj.Parent:findFirstChild("Humanoid") then
  216. table.insert(_G.AntiJumpCache, obj.Parent)
  217. else
  218. return true
  219. end
  220. --add to cache if necessary, otherwise recurse
  221. return objAhead(loc)
  222. end
  223. end
  224.  
  225. function ai.canSee(obj, fov)
  226. local direction = (obj.Position - ai.Model.Head.Position).unit
  227. if fov and direction:Dot(ai.Model.Head.CFrame.lookVector) < math.cos(math.rad(fov)) then
  228. return false
  229. end
  230. local ray = Ray.new(ai.Model.Head.Position, direction * 900)
  231. local hit, pos = workspace:FindPartOnRayWithIgnoreList(ray, {ai.Model})
  232. if hit then
  233. --add to cache if transparent?
  234. if hit == obj then
  235. return true
  236. end
  237. end
  238. end
  239.  
  240. function attack(hum)
  241. print("pow")
  242. lastAttack = time()
  243. hum:TakeDamage(atkDamage)
  244. end
  245.  
  246. function initialize()
  247. for _, obj in pairs(ai.Model:GetChildren()) do
  248. if obj:IsA("BasePart") then
  249. obj.Anchored = false
  250. end
  251. end
  252. setHeight(2, 1)
  253. ai.tWeld = weld(ai.Model.Torso, ai.Model.torso, CFrame.new(0,-1,0), CFrame.new(0,-1,0) * CFrame.Angles(math.rad(45),0,0))
  254. ai.hWeld = weld(ai.Model.torso, ai.Model.head2, CFrame.new(0,.8,0), CFrame.new(0,-.6,0) * CFrame.Angles(math.rad(-22.5),0,0))
  255. ai.lWeld1 = weld(ai.Model.torso, ai.Model.leftLeg, CFrame.new(-0.5,-1,0), CFrame.new(0,1,0) * CFrame.Angles(math.rad(-45),0,0))
  256. ai.lWeld2 = weld(ai.Model.torso, ai.Model.rightLeg, CFrame.new(0.5,-1,0), CFrame.new(0,1,0) * CFrame.Angles(math.rad(-45),0,0))
  257. ai.aWeld1 = weld(ai.Model.torso, ai.Model.leftArm, CFrame.new(-1,0.5,0), CFrame.new(0.5,0.5,0) * CFrame.Angles(math.rad(-45),0,0))
  258. ai.aWeld2 = weld(ai.Model.torso, ai.Model.rightArm, CFrame.new(1,0.5,0), CFrame.new(-0.5,0.5,0) * CFrame.Angles(math.rad(-45),0,0))
  259. ai.HWeld = weld(ai.Model.Torso, ai.Model.Head)
  260. anim(math.rad(20),0,0)
  261. ai.Humanoid = Instance.new("Humanoid", ai.Model)
  262. ai.Humanoid.WalkSpeed = math.random(8,14) + math.max(0, math.random(-5,3))
  263. ai.State = "Idle"
  264. ai.Model.ChildRemoved:connect(delete)
  265. ai.Humanoid.Died:connect(delete)
  266. ai.Humanoid.Running:connect(animate)
  267. table.insert(_G.aiTable, ai)
  268. end
  269.  
  270. function delete()
  271. wait(0)
  272. if not ai.Humanoid or not (ai.Humanoid.Health > 0) or not ai.Model:findFirstChild("Torso") or not ai.Model:FindFirstChild("Head") or not ai.Model:FindFirstChild("head2") then
  273. for i, a in pairs(_G.aiTable) do
  274. if a == ai then
  275. table.remove(_G.aiTable, i)
  276. end
  277. end
  278. ai.Model:BreakJoints()
  279. game.Debris:AddItem(ai.Model, 3)
  280. for i, obj in pairs(ai.Model:GetChildren()) do
  281. if obj:IsA("BasePart") and obj.Transparency ~= 1 then
  282. obj.CanCollide = true
  283. elseif obj ~= script then
  284. obj:Destroy()
  285. end
  286. end
  287. ai = nil
  288. goalPos = nil
  289. elseif not (ai.Model:FindFirstChild("leftLeg") and ai.Model:FindFirstChild("rightLeg")) and not crawling then
  290. crawl()
  291. end
  292. if ai and crawling and not (ai.Model:FindFirstChild("leftArm") and ai.Model:FindFirstChild("rightArm")) then
  293. ai.Humanoid.Health = 0
  294. end
  295. end
  296.  
  297. function animate(a)
  298. if not running2 then
  299. running = a > 0
  300. if running then
  301. Spawn(function()
  302. running2 = true
  303. local start = time()
  304. while running do
  305. wait(0)
  306. local cycle = (tick() - start) * 5
  307. local tPitch = math.rad(25 + math.cos(cycle * 2) * -5)
  308. local tRoll = math.rad(math.sin(cycle) * 10)
  309. local lPitch = math.rad(math.sin(cycle) * 45)
  310. anim(tPitch, tRoll, lPitch)
  311. end
  312. running2 = false
  313. anim(math.rad(20),0,0)
  314. end)
  315. end
  316. else
  317. running = a > 0
  318. end
  319. end
  320.  
  321. function anim(tPitch, tRoll, lPitch)
  322. if not ai then return end
  323. local crawlMod = crawling and math.rad(50) or 0
  324. local crawlMod2 = crawling and 4 or 1
  325. local attackMod = (attackTime - math.min(attackTime,(time() - lastAttack)))/attackTime * math.rad(140)
  326. lPitch2 = crawling and lPitch / 3 or lPitch
  327. if ai.tWeld then
  328. ai.tWeld.C1 = CFrame.new(0,-1,0) * CFrame.Angles(tPitch + crawlMod,0,tRoll + limp[1] * .4)
  329. end
  330. if ai.hWeld then
  331. ai.hWeld.C1 = CFrame.new(0,-0.6,0) * CFrame.Angles(-tPitch/2,0,tRoll + limp[2] * .4)
  332. end
  333. if ai.lWeld1 then
  334. ai.lWeld1.C1 = CFrame.new(0,1,0) * CFrame.Angles(lPitch2 - tPitch + crawlMod + limp[3] * .4,0,-tRoll - limp[1] * .4)
  335. end
  336. if ai.lWeld2 then
  337. ai.lWeld2.C1 = CFrame.new(0,1,0) * CFrame.Angles(-lPitch2 - tPitch + crawlMod + limp[4] * .4,0,-tRoll - limp[1] * .4)
  338. end
  339. if ai.aWeld1 then
  340. ai.aWeld1.C1 = CFrame.new(0.5,0.5,0) * CFrame.Angles(0,0, crawlMod/2) * CFrame.Angles(lPitch * math.abs(limp[5]) * -0.4 * crawlMod2 - tPitch - crawlMod - attackMod + limp[5] * .2, 0, -tRoll - limp[1] * .4)
  341. end
  342. if ai.aWeld2 then
  343. ai.aWeld2.C1 = CFrame.new(-0.5,0.5,0) * CFrame.Angles(0,0, -crawlMod/2) * CFrame.Angles(lPitch * math.abs(limp[6]) * 0.4 * crawlMod2 - tPitch - crawlMod - attackMod + limp[6] * .2, 0, -tRoll - limp[1] * .4)
  344. end
  345. if ai.HWeld and ai.Model:findFirstChild("head2") then
  346. ai.HWeld.C0 = ai.Model.Torso.CFrame:toObjectSpace(ai.Model.head2.CFrame)
  347. end
  348. end
  349.  
  350. function crawl()
  351. crawling = true
  352. setHeight(0,0)
  353. ai.Humanoid.WalkSpeed = math.random(4, 6)
  354. end
  355.  
  356. while not _G.aiTable do
  357. wait(0)
  358. end
  359. initialize()
  360. end))
  361. Part8.Name = "rightLeg"
  362. Part8.Parent = Model3
  363. Part8.CFrame = CFrame.new(-11.699996, 1.00001299, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  364. Part8.Position = Vector3.new(-11.699996, 1.00001299, -16.1000061)
  365. Part8.Color = Color3.new(1, 0, 0)
  366. Part8.Size = Vector3.new(1, 2, 0.99999994)
  367. Part8.Anchored = true
  368. Part8.BottomSurface = Enum.SurfaceType.Smooth
  369. Part8.BrickColor = BrickColor.new("Really red")
  370. Part8.CanCollide = false
  371. Part8.TopSurface = Enum.SurfaceType.Smooth
  372. Part8.brickColor = BrickColor.new("Really red")
  373. Part8.FormFactor = Enum.FormFactor.Custom
  374. Part8.formFactor = Enum.FormFactor.Custom
  375. Part9.Name = "leftLeg"
  376. Part9.Parent = Model3
  377. Part9.CFrame = CFrame.new(-12.699996, 1.00001299, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  378. Part9.Position = Vector3.new(-12.699996, 1.00001299, -16.1000061)
  379. Part9.Color = Color3.new(1, 0, 0)
  380. Part9.Size = Vector3.new(1, 2, 0.99999994)
  381. Part9.Anchored = true
  382. Part9.BottomSurface = Enum.SurfaceType.Smooth
  383. Part9.BrickColor = BrickColor.new("Really red")
  384. Part9.CanCollide = false
  385. Part9.TopSurface = Enum.SurfaceType.Smooth
  386. Part9.brickColor = BrickColor.new("Really red")
  387. Part9.FormFactor = Enum.FormFactor.Custom
  388. Part9.formFactor = Enum.FormFactor.Custom
  389. Part10.Name = "leftArm"
  390. Part10.Parent = Model3
  391. Part10.CFrame = CFrame.new(-13.7000055, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  392. Part10.Position = Vector3.new(-13.7000055, 3.00001192, -16.1000061)
  393. Part10.Color = Color3.new(1, 0, 0)
  394. Part10.Size = Vector3.new(1, 2, 0.99999994)
  395. Part10.Anchored = true
  396. Part10.BottomSurface = Enum.SurfaceType.Smooth
  397. Part10.BrickColor = BrickColor.new("Really red")
  398. Part10.CanCollide = false
  399. Part10.TopSurface = Enum.SurfaceType.Smooth
  400. Part10.brickColor = BrickColor.new("Really red")
  401. Part10.FormFactor = Enum.FormFactor.Custom
  402. Part10.formFactor = Enum.FormFactor.Custom
  403. Part11.Name = "torso"
  404. Part11.Parent = Model3
  405. Part11.CFrame = CFrame.new(-12.199996, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  406. Part11.Position = Vector3.new(-12.199996, 3.00001192, -16.1000061)
  407. Part11.Color = Color3.new(1, 0, 0)
  408. Part11.Size = Vector3.new(2, 2, 0.99999994)
  409. Part11.Anchored = true
  410. Part11.BottomSurface = Enum.SurfaceType.Smooth
  411. Part11.BrickColor = BrickColor.new("Really red")
  412. Part11.CanCollide = false
  413. Part11.Locked = true
  414. Part11.TopSurface = Enum.SurfaceType.Smooth
  415. Part11.brickColor = BrickColor.new("Really red")
  416. Part11.FormFactor = Enum.FormFactor.Custom
  417. Part11.formFactor = Enum.FormFactor.Custom
  418. Part12.Name = "rightArm"
  419. Part12.Parent = Model3
  420. Part12.CFrame = CFrame.new(-10.699996, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  421. Part12.Position = Vector3.new(-10.699996, 3.00001192, -16.1000061)
  422. Part12.Color = Color3.new(1, 0, 0)
  423. Part12.Size = Vector3.new(1, 2, 0.99999994)
  424. Part12.Anchored = true
  425. Part12.BottomSurface = Enum.SurfaceType.Smooth
  426. Part12.BrickColor = BrickColor.new("Really red")
  427. Part12.CanCollide = false
  428. Part12.TopSurface = Enum.SurfaceType.Smooth
  429. Part12.brickColor = BrickColor.new("Really red")
  430. Part12.FormFactor = Enum.FormFactor.Custom
  431. Part12.formFactor = Enum.FormFactor.Custom
  432. Part13.Name = "head2"
  433. Part13.Parent = Model3
  434. Part13.CFrame = CFrame.new(-12.199996, 4.50000381, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  435. Part13.Position = Vector3.new(-12.199996, 4.50000381, -16.1000061)
  436. Part13.Color = Color3.new(1, 0, 0)
  437. Part13.Size = Vector3.new(1, 1, 1)
  438. Part13.Anchored = true
  439. Part13.BottomSurface = Enum.SurfaceType.Smooth
  440. Part13.BrickColor = BrickColor.new("Really red")
  441. Part13.CanCollide = false
  442. Part13.TopSurface = Enum.SurfaceType.Smooth
  443. Part13.brickColor = BrickColor.new("Really red")
  444. Part13.FormFactor = Enum.FormFactor.Custom
  445. Part13.formFactor = Enum.FormFactor.Custom
  446. SpecialMesh14.Parent = Part13
  447. SpecialMesh14.Scale = Vector3.new(1.39999998, 1.39999998, 1.39999998)
  448. Decal15.Name = "Rage Face"
  449. Decal15.Parent = Part13
  450. Decal15.Texture = "http://www.roblox.com/asset/?id=109676489"
  451. Script16.Name = "Controller"
  452. Script16.Parent = Model0
  453. table.insert(cors,sandbox(Script16,function()
  454. _G.aiTable = {}
  455.  
  456. while wait(.1) do
  457. for i, ai in pairs(_G.aiTable) do
  458. if ai ~= nil and ai.State == "Idle" then
  459. local closestChar
  460. local closestDist = 200 -- Edit this value, it changes how close you have to be to the zombie for it to attack or "see" you.
  461. local pos = ai.Model:GetModelCFrame().p
  462. for j, player in pairs(game.Players:GetPlayers()) do
  463. if player.Character and player.Character:findFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
  464. local dist = (player.Character:GetModelCFrame().p - pos).magnitude
  465. if dist <= closestDist then
  466. for _, obj in pairs(player.Character:GetChildren()) do
  467. if obj:IsA("BasePart") and (ai.canSee(obj, 85) or ai.canSee(obj) and dist <= 10)then
  468. closestChar = player.Character
  469. closestDist = dist
  470. break
  471. end
  472. end
  473. end
  474. end
  475. end
  476. if closestChar then
  477. ai.Move(closestChar, true, closestChar:findFirstChild("Humanoid"))
  478. elseif math.random() > 0.8 then
  479. local dir = CFrame.Angles(0,math.random() * math.pi * 2,0).lookVector
  480. local _, pos = workspace:FindPartOnRay(Ray.new(ai.Model:GetModelCFrame().p, dir * math.random(10,20)), ai.Model)
  481. pos = pos - dir * 5
  482. ai.Move(pos)
  483. end
  484. end
  485. end
  486. end
  487. end))
  488. for i,v in pairs(mas:GetChildren()) do
  489. v.Parent = script
  490. pcall(function() v:MakeJoints() end)
  491. end
  492. mas:Destroy()
  493. for i,v in pairs(cors) do
  494. spawn(function()
  495. pcall(v)
  496. end)
  497. end
Advertisement
Add Comment
Please, Sign In to add comment