Tower Defense Targeting Glitch

Code:
`return function(t, blackList)
local Furthest = 0
local Target = nil

for enemy_model, enemy_data in pairs(_G.enemies) do
	if blackList then
		if table.find(blackList, enemy_data.Hash) then continue end
	end
		if (enemy_data.Position-t.CFrame.Position).Magnitude > t.Data.Range then
			continue 
		end
		if t.Target == "First" then
			
			if enemy_data.Alpha > Furthest then
			Furthest = enemy_data.Alpha
				Target = enemy_data

			end
		elseif t.Target == "Last" then
			if enemy_data.Alpha < Furthest then
				Furthest = enemy_data.Alpha
				Target = enemy_data
			end
		end
	return Target
	end

end

Problem is that its not stable when there are less enemies intended it works but alot of enemies just is not the case. i need this fixed really! word of help can be useful !

VIDEO VISA(my friend recorded):


as you can see it passes the front enemy!

`

1 Like

in the video target is set to First and still targeting randomly.