My npc not properly moving to the face of a part?

I have an issue where I try to make an npc move to behind a part based on the normal. Here’s the code I have for finding the normal

function NormalToFace(normalVector, part)

    local TOLERANCE_VALUE = 1 - 0.001
    local allFaceNormalIds = {
        Enum.NormalId.Front,
        Enum.NormalId.Back,
        Enum.NormalId.Bottom,
        Enum.NormalId.Top,
        Enum.NormalId.Left,
        Enum.NormalId.Right
    }    

    for _, normalId in pairs( allFaceNormalIds ) do
        -- If the two vectors are almost parallel,
        if GetNormalFromFace(part, normalId):Dot(normalVector) > TOLERANCE_VALUE then
            return normalId -- We found it!
        end
    end

    return nil -- None found within tolerance.

end

function GetNormalFromFace(part, normalId)
    return part.CFrame:VectorToWorldSpace(Vector3.FromNormalId(normalId))
end

the code for actually calling the functions

local normalID = NormalToFace(ResultLeft.Position, ResultLeft.Instance)
print(normalID)
print(Vector3.FromNormalId(normalID))

local dir = Vector3.FromNormalId(normalID) * -10
moveTo(myRoot.CFrame:PointToWorldSpace(dir))
print(myRoot.CFrame:PointToWorldSpace(dir))
local Part = Instance.new("Part", workspace)
Part.Size = Vector3.new(1,1,1)
Part.Anchored = true
Part.Material = "Neon"
Part.BrickColor = BrickColor.new("Neon orange")
Part.Position = myRoot.CFrame:PointToWorldSpace(dir)
Part.Name = "MachineGunnerCoverPart"
Part.CanCollide = false

I want the npc to go like this:

but he goes like this:

If anyone could tell me what I’m doing wrong, it would be greatly appreciated!

1 Like

Have you tried putting prints in to confirm the logic flows as you expect.
I see you have printed the result of normalid but what if its nil?
Perhaps print out the value returned from GetNormalFromFace;

I have done all of these things.
The parts that I create always appear at the position he moves to, and never where I want it to. It’s confusing

What is the value of ResultLeft and subsequent normalID?