Need help finding three closest points in a triangle

how can i check that the three closest points i find are in a triangle?
if the red dot is here:


then it would get the correct positions

then it would get this, which wouldn’t be correct at all :confused:

here’s my function, im just trying to find a quick solution as im working on a bigger one, but for now i want a small one


local function FindClosestPoints2(OriginalPos)
	local Distances = {}
	
	for Bone,Position in pairs(Origins) do
		Distances[#Distances + 1] = {Object = Bone; Distance = (Bone.TransformedWorldCFrame.Position - OriginalPos).Magnitude}
	end
	
	table.sort(Distances,function(a,b)
		return a.Distance < b.Distance
	end)
	
	return {table.unpack(Distances)}
end

any help is nice