Is this NPC unoptimized? help needed

So, I just made an NPC that roams the map, and I wanted to know if I could do this better. the main thing I want help with is this:

local List = {}
	for _, Part in pairs(script.Paths.Value:GetChildren()) do
		if Part:IsA("BasePart") and (Part.Position - humanoid.RootPart.Position).Magnitude < 200 then
			table.insert(List,Part)
		end
	end
	if #List > 0 then
		CurrentDestination = List[math.random(1,#List)]
	else
		warn("an NPC failed to find a path")
		Character:Destroy()
	end

there are about 200 hundred locations. all they do is simply walk to it.
here is the code for walking to it:

while wait() do 
	local target = findTarget()
	CDMGCD += .1
	if humanoid.Health == 0 then
		break
	end
	if target and GlobalValues.IsDay.Value == false then
		humanoid.WalkSpeed = 16
		followPath(target.HumanoidRootPart.Position)
	else
		humanoid.WalkSpeed = 10
		if CurrentDestination == nil then
			GetCurrentDestination()
		end
		if (CurrentDestination.Position - humanoid.RootPart.Position).Magnitude < 5 then
			GetCurrentDestination()
		end
		followPath(CurrentDestination.Position)
	end
end

the followPath function is just a simple pathfind

there is also about 15 npc in the map at a time

the wait() is pretty unoptimized and got replaced by task.wait() which is 2x accurate.

explanation here

anyway, i dont recommend to use a while loop, instead, use game.Runservice.RenderStepped

it will run every frame after the physic got simulated first, basically is what you need
(dont worry, it doesnt lag)

by the way, you did a good job

well, I need it to run .1 second specifically.

local target = findTarget()
	CDMGCD += .1
	LastHit += .1
	SinceGoodPath -= .1
	if humanoid.Health == 0 then
		break
	end
	if target and GlobalValues.IsDay.Value == false then
		humanoid.WalkSpeed = 16
		followPath(target.HumanoidRootPart.Position)
	else
		humanoid.WalkSpeed = 10
		if CurrentDestination == nil then
			GetCurrentDestination()
		end
		if (CurrentDestination.Position - humanoid.RootPart.Position).Magnitude < 5 or SinceGoodPath <= 0 then
			GetCurrentDestination()
			SinceGoodPath = 20
		end
		local p = followPath(CurrentDestination.Position)
		if p == false then
			print("Forced Move")
			GetCurrentDestination()
			followPath(CurrentDestination.Position)
		end
	end
	if LastHit > 5 then
		nextWaypointIndex += 1
		LastHit = 0
		print("Hit Reset")
	end

I’m having some big issues right now with them getting stuck

Also while loops on server are better than performing stuff every frame, you don’t need soo much precision, make calculation every 10-15 frames

Apparently my game or npcs ain’t optimized enough, cause I did a test with my friends and the server took about 5 seconds to receive an event.