local W=game:GetService("\082\117\110\083\101\114\118\105\099\101")while W.Heartbeat:Wait()do local W=1000 local y for d,r in pairs(game.Players:GetPlayers())do if r.Character and(r.Character:FindFirstChild("\072\117\109\097\110\111\105\100")and(r.Character.Humanoid.Health>0 and r.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")))then local d=(rootpart.Position-r.Character.HumanoidRootPart.Position).magnitude if W>d then W=d y=r.Character.HumanoidRootPart end end end for d,r in pairs(npc:GetChildren())do if r:FindFirstChild("\122\111\109\098\105\101")==nil and(r:FindFirstChild("\072\117\109\097\110\111\105\100")and(r.Humanoid.Health>0 and r:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")))then local d=(rootpart.Position-r.HumanoidRootPart.Position).magnitude if W>d then W=d y=r.HumanoidRootPart end end end if y then humanoid:MoveTo(y.Position)end end

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
