Advertisement
Guest User

Untitled

a guest
Jul 16th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. --]]
  2.  
  3.  
  4. local SearchDistance = 100 -- How far a player can be before it detects you
  5.  
  6. local ZombieDamage = 100 -- How much damage the Zombie inficts towards the player
  7. local DamageWait = 1 -- How many seconds to wait before it can damage the player again
  8.  
  9. local WanderX, WanderZ = 70, 70
  10. -- How many studs the zombie can wander on the x and z axis in studs ; 0, 0 to stay still
  11.  
  12. --[[
  13. ____________________________________________________________________________________________________________________
  14.  
  15. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  16. ____________________________________________________________________________________________________________________
  17.  
  18. --]]
  19.  
  20.  
  21. function getHumanoid(model)
  22. for _, v in pairs(model:GetChildren())do
  23. if v:IsA'Humanoid' then
  24. return v
  25. end
  26. end
  27. end
  28.  
  29.  
  30. local zombie = script.Parent
  31. local human = getHumanoid(zombie)
  32. local hroot = zombie.Torso
  33. local zspeed = hroot.Velocity.magnitude
  34. local head = zombie:FindFirstChild'Head'
  35. local vars = script.vars
  36.  
  37. local pfs = game:GetService("PathfindingService")
  38. local players = game:GetService('Players')
  39.  
  40. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  41.  
  42. local path
  43. local waypoint
  44.  
  45. local chaseName = nil
  46.  
  47. function GetTorso(part)
  48. local chars = game.Workspace:GetChildren()
  49. local chaseRoot = nil
  50. local chaseTorso = nil
  51. local chasePlr = nil
  52. local chaseHuman = nil
  53. local mag = SearchDistance
  54. for i = 1, #chars do
  55. chasePlr = chars[i]
  56. if chasePlr:IsA'Model' and chasePlr ~= zombie then
  57. chaseHuman = getHumanoid(chasePlr)
  58. chaseRoot = chasePlr:FindFirstChild'HumanoidRootPart'
  59. if chaseRoot ~= nil and chaseHuman ~= nil and chaseHuman.Health > 0 and chaseHuman.Name ~= "Zombie" then
  60. if (chaseRoot.Position - part).magnitude < mag then
  61. chaseName = chasePlr.Name
  62. chaseTorso = chaseRoot
  63. mag = (chaseRoot.Position - part).magnitude
  64. end
  65. end
  66. end
  67. end
  68. return chaseTorso
  69. end
  70.  
  71. function GetPlayersBodyParts(t)
  72. local torso = t
  73. if torso then
  74. local figure = torso.Parent
  75. for _, v in pairs(figure:GetChildren())do
  76. if v:IsA'Part' then
  77. return v.Name
  78. end
  79. end
  80. else
  81. return "HumanoidRootPart"
  82. end
  83. end
  84.  
  85. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  86.  
  87. local damagetime
  88. local damagedb = false
  89.  
  90. for _, zambieparts in pairs(zombie:GetChildren())do
  91. if zambieparts:IsA'Part' and human.Health > 0 then
  92. zambieparts.Touched:connect(function(p)
  93. if p.Parent.Name == chaseName and p.Parent.Name ~= zombie.Name and not damagedb then -- damage
  94. damagedb = true
  95. damagetime = time()
  96. local enemy = p.Parent
  97. local enemyhuman = getHumanoid(enemy)
  98. vars.Attacking.Value = true
  99. enemyhuman:TakeDamage(ZombieDamage)
  100. vars.Attacking.Value = false
  101. while wait() do
  102. if damagetime ~= nil and time() >= (damagetime + DamageWait) then
  103. damagedb = false
  104. damagetime = nil
  105. end
  106. end
  107. end
  108. end)
  109. end
  110. end
  111.  
  112. -- wandering
  113. spawn(function()
  114. while vars.Wandering.Value == false and human.Health > 0 do
  115. vars.Chasing.Value = false
  116. vars.Wandering.Value = true
  117. local desgx, desgz = hroot.Position.x+math.random(-WanderX,WanderX), hroot.Position.z+math.random(-WanderZ,WanderZ)
  118. local function checkw(t)
  119. local ci = 3
  120. if ci > #t then
  121. ci = 3
  122. end
  123. if t[ci] == nil and ci < #t then
  124. repeat ci = ci + 1 wait() until t[ci] ~= nil
  125. return Vector3.new(1,0,0) + t[ci]
  126. else
  127. ci = 3
  128. return t[ci]
  129. end
  130. end
  131.  
  132. path = pfs:FindPathAsync(hroot.Position, Vector3.new(desgx, 0, desgz))
  133. waypoint = path:GetWaypoints()
  134. local connection;
  135.  
  136. local direct = Vector3.FromNormalId(Enum.NormalId.Front)
  137. local ncf = hroot.CFrame * CFrame.new(direct)
  138. direct = ncf.p.unit
  139. local rootr = Ray.new(hroot.Position, direct)
  140. local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
  141.  
  142. if path and waypoint or checkw(waypoint) then
  143. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
  144. human:MoveTo( checkw(waypoint).Position )
  145. human.Jump = false
  146. end
  147.  
  148. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
  149. connection = human.Changed:connect(function()
  150. human.Jump = true
  151. end)
  152. human:MoveTo( waypoint[4].Position )
  153. else
  154. human.Jump = false
  155. end
  156.  
  157. if connection then
  158. connection:Disconnect()
  159. end
  160.  
  161. else
  162. for i = 3, #waypoint do
  163. human:MoveTo( waypoint[i].Position )
  164. end
  165. end
  166. wait(math.random(4,6))
  167. vars.Wandering.Value = false
  168. end
  169. end)
  170.  
  171. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  172.  
  173. while wait() do
  174. local nrstt = GetTorso(hroot.Position)
  175. if nrstt ~= nil and human.Health > 0 then -- if player detected
  176. vars.Wandering.Value = false
  177. vars.Chasing.Value = true
  178. local function checkw(t)
  179. local ci = 3
  180. if ci > #t then
  181. ci = 3
  182. end
  183. if t[ci] == nil and ci < #t then
  184. repeat ci = ci + 1 wait() until t[ci] ~= nil
  185. return Vector3.new(1,0,0) + t[ci]
  186. else
  187. ci = 3
  188. return t[ci]
  189. end
  190. end
  191.  
  192. path = pfs:FindPathAsync(hroot.Position, nrstt.Position)
  193. waypoint = path:GetWaypoints()
  194. local connection;
  195.  
  196. local direct = Vector3.FromNormalId(Enum.NormalId.Front)
  197. local ncf = hroot.CFrame * CFrame.new(direct)
  198. direct = ncf.p.unit
  199. local rootr = Ray.new(hroot.Position, direct)
  200. local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
  201.  
  202. if path and waypoint or checkw(waypoint) then
  203. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
  204. human:MoveTo( checkw(waypoint).Position )
  205. human.Jump = false
  206. end
  207.  
  208. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
  209. connection = human.Changed:connect(function()
  210. human.Jump = true
  211. end)
  212. human:MoveTo( waypoint[4].Position )
  213. else
  214. human.Jump = false
  215. end
  216.  
  217. hroot.Touched:connect(function(p)
  218. local bodypartnames = GetPlayersBodyParts(nrstt)
  219. if p:IsA'Part' and not p.Name == bodypartnames and phit and phit.Name ~= bodypartnames and phit:IsA'Part' and rootr:Distance(phit.Position) < 5 then
  220. connection = human.Changed:connect(function()
  221. human.Jump = true
  222. end)
  223. else
  224. human.Jump = false
  225. end
  226. end)
  227.  
  228. if connection then
  229. connection:Disconnect()
  230. end
  231.  
  232. else
  233. for i = 3, #waypoint do
  234. human:MoveTo( waypoint[i].Position )
  235. end
  236. end
  237. path = nil
  238. waypoint = nil
  239. elseif nrstt == nil then -- if player not detected
  240. vars.Wandering.Value = false
  241. vars.Chasing.Value = false
  242. CchaseName = nil
  243. path = nil
  244. waypoint = nil
  245. human.MoveToFinished:Wait()
  246. end
  247. end
  248.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement