the model shakes when there is two or more target its confused on where to go i think, how do i fixed it.

local plane = script.Parent.Parent
local eng = script.Parent.Engine
local trail = script.Parent.Fire
local gun = script.Parent.Gun
local target = ""
local backup = plane:Clone()
local parts = {gun, eng, trail}
local c = plane.BodyKit:GetChildren()
for i = 1, #c do
	table.insert(parts, c[i])
end


function onDie()
	if connection ~= nil then
		connection:disconnect()
	end
	local c = game.Workspace:GetChildren()
	local ore = {}
	for i = 1, #c do
		if c[i]:FindFirstChild("Htitanium") ~= nil and c[i] ~= target and c[i].Htitanium.Health > 0 and plane.Immune:FindFirstChild(c[i].Name) == nil then
			table.insert(ore, c[i])
		end
	end
	if #ore == 0 then
		
		return
	end
	local a = 500
	for i = 1, #ore do
		local mag = (ore[i].Ore.Position - eng.Position).magnitude
		if mag < a then
			a = mag
		end
	end
	for i = 1, #ore do
		if (ore[i].Ore.Position - eng.Position).magnitude == a then
			target = ore[i]
		end
	end
	connection = target.Htitanium.Died:connect(onDie)
end



function clean()
	wait(0.5)
	script.Parent = workspace
	plane:Remove()
	local c = backup:Clone()
	wait(2.5)
	c.Parent = workspace
	c:MakeJoints()
	script:Remove()
end



while true do
	if (eng.Position - gun.Position).magnitude >= 10 then
		eng.BodyPosition.maxForce = Vector3.new(0,0,0)
		plane:BreakJoints()
		for i = 1, #parts do
			parts[i].RotVelocity = Vector3.new(math.random(-25,25),math.random(-25,25),math.random(-25,25))
			parts[i].CFrame = eng.CFrame + Vector3.new(math.random(-2,2),math.random(-2,2),math.random(-2,2))
			local bv = Instance.new("BodyVelocity")
			bv.Parent = parts[i]
			bv.velocity = parts[i].Position - eng.Position
		end
		clean()
		break
	end
	eng.BodyPosition.position = eng.Position + eng.CFrame.lookVector
	onDie()
	if target ~= "" then
		eng.BodyGyro.cframe = CFrame.new(eng.Position, target.Ore.Position)
		local a = math.random(0,10)
		
	end

	wait(0.1)
end