Hasli4

RBLX. Seeking

Jan 9th, 2026
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. local Pirate = script.Parent.PirateType
  2.  
  3.  
  4. function findNearestTorso(pos)
  5.  
  6.         local list = game.Workspace:children()
  7.  
  8.         local torso = nil
  9.  
  10.         local dist = 50 --This Line Right Here
  11.  
  12.         local temp = nil
  13.  
  14.         local human = nil
  15.  
  16.         local temp2 = nil
  17.  
  18.         for x = 1, #list do
  19.  
  20.                 temp2 = list[x]
  21.  
  22.                 if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  23.  
  24.                         temp = temp2:findFirstChild("Head")
  25.  
  26.                         human = temp2:findFirstChild("Humanoid")
  27.  
  28.                         local Friend = temp2:findFirstChild("Friend")
  29.  
  30.                         if (temp ~= nil) and (human ~= nil) and (Friend == nil) or (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (Friend.Value ~= script.Parent.Friend.Value) then
  31.  
  32.                                 if (temp.Position - pos).magnitude < dist then
  33.  
  34.                                         torso = temp
  35.  
  36.                                         dist = (temp.Position - pos).magnitude
  37.  
  38.                                 end
  39.  
  40.                         end
  41.  
  42.                 end
  43.  
  44.         end
  45.  
  46.         return torso
  47.  
  48. end
  49.  
  50. while true do
  51.  
  52.         wait(0.1)
  53.  
  54.         local target = findNearestTorso(script.Parent.UpperTorso.Position)
  55.  
  56.         if target ~= nil then
  57.  
  58.                 Pirate.WalkSpeed = script.Parent.Parent.WalkSpeed.Value
  59.  
  60.                 script.Parent.PirateType:MoveTo(target.Position, target)
  61.  
  62.         end
  63.  
  64. end
  65.  
  66.  
  67.  
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment