Sungmingamerpro13

Chase to Player (MonsterScript) Normal Script

Jan 26th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 0.92 KB | None | 0 0
  1. local larm = script.Parent:FindFirstChild("HumanoidRootPart")
  2. local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
  3.  
  4. function findNearestTorso(pos)
  5.     local list = game.Workspace:children()
  6.     local torso = nil
  7.     local dist = 10000
  8.     local temp = nil
  9.     local human = nil
  10.     local temp2 = nil
  11.     for x = 1, #list do
  12.         temp2 = list[x]
  13.         if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  14.             temp = temp2:findFirstChild("HumanoidRootPart")
  15.             human = temp2:findFirstChild("Humanoid")
  16.             if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  17.                 if (temp.Position - pos).magnitude < dist then
  18.                     torso = temp
  19.                     dist = (temp.Position - pos).magnitude
  20.                 end
  21.             end
  22.         end
  23.     end
  24.     return torso
  25. end
  26.  
  27.  
  28.  
  29.  
  30. while true do
  31.     wait(1)
  32.     local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
  33.     if target ~= nil then
  34.         script.Parent.Zombie:MoveTo(target.Position, target)
  35.     end
  36.  
  37. end
  38.  
Add Comment
Please, Sign In to add comment