How do I fix the tower's target

Hello, I have a problem with the turret, it shoots at the target which I didn’t want. I’ve used to look some topic that look familiar to mine but I still can’t figure it out so, I want my turret to target the first enemy, please guide me.

Thank for your help!

Here’s a video
robloxapp-#####-#####.wmv (5.0 MB)

and here’s my code

while wait(script.Parent.Parent.CooldownInSec.Value) do
	local NearbyEnemies = {}
	local Point = {}
	local NPCMagnitude = {}
	for i,v in pairs(workspace.Enemies:GetChildren()) do
		local dis = (v.Position - script.Parent.Position).magnitude
		local nodedis = (v.Position - workspace.PathWay["D"..v.CurrentPoint.Value].Position).magnitude
		if dis <= Range/2 then
			if v.Name ~= "Arrow"  then
				--table.insert(NearbyEnemies,v.Name)
				table.insert(Point,v.CurrentPoint.Value.." "..nodedis.." "..v.Name)
				table.sort(Point)
				local sepSpace1 = string.find(Point[#Point]," ")
				local sepSpace2 = string.find(Point[#Point]," ",sepSpace1+1)
				local PointCheck = tonumber(string.sub(Point[#Point],1,sepSpace1-1))
				local MagCheck = tonumber(string.sub(string.sub(Point[#Point],sepSpace1+1,sepSpace2-1),1,5))
			--	local EnemyName = string.sub(Point[#Point],sepSpace2)
				local forRealMag = tonumber(string.sub(nodedis,1,5))
				--for p,l in pairs(workspace.Enemies:GetChildren()) do
			--	print(EnemyName)
				if MagCheck == forRealMag and v.CurrentPoint.Value == PointCheck then 
					print(1)
					--if v.Name == EnemyName then
					warn("WORKING WOHO")
					--print(v.Name)
						ShootTarget(v.Name)
						break
					--	end
					end
				--end
			end	
		end
	end
	--print(table.concat(Point," "))
end

Ok, I know my code have no performance, I’m going to rewrite this later.

My friend has solved this out, Thank you.