Advertisement
Guest User

Scriptsdsa

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