-----------------

local runservice = game:GetService("RunService")
while runservice.Heartbeat:Wait() do
	local distance = 1000 -- 사람 인식하는 최대 범위
	local target
	for i, v in pairs(game.Players:GetPlayers())do
		if v.Character and v.Character:FindFirstChild("Humanoid") 
			and v.Character.Humanoid.Health > 0 
			and v.Character:FindFirstChild("HumanoidRootPart")then
			local d = (rootpart.Position - v.Character.HumanoidRootPart.Position).magnitude
			if distance > d then
				distance = d
				target = v.Character.HumanoidRootPart
			end
		end
	end
	for i, v in pairs(npc:GetChildren())do
		if v:FindFirstChild("zombie") == nil and v:FindFirstChild("Humanoid")
			and v.Humanoid.Health > 0 
			and v:FindFirstChild("HumanoidRootPart")then
			local d = (rootpart.Position - v.HumanoidRootPart.Position).magnitude
			if distance > d then
				distance = d
				target = v.HumanoidRootPart
			end
		end
	end
	if target then
		humanoid:MoveTo(target.Position)
	end
end
