this is for the player but i want it or the npc

local torso = script.Parent.HumanoidRootPart
local h = script.Parent.Humanoid
local spawnCF = script.Parent.HumanoidRootPart.CFrame
local att = false
local cooldwon = false
--------------------------------------tabel
 Namet = {"run","attack"}
Namet.run = h:LoadAnimation(script.Parent.Animations.run)
----------------------------------

Namet.run:Play()
function findplayer()
 for _,v in next,game.Workspace:GetChildren() do -- this is what i  tried to do 
  if v.Character then
   local char = v.Character
   if char:FindFirstChild("Humanoid")and char:FindFirstChild("HumanoidRootPart") then
    local ptorso = char.HumanoidRootPart

    if(ptorso.position - torso.Position).magnitude <= 27 then
   return v
    end
   end
  end
 end
 return nil
end

while wait()do
 local player = findplayer()
 if player ~= nil then
      h:MoveTo(player.Character.HumanoidRootPart.position)
	
end


end