Basepart not facing Enemy Player

  1. Hello!, I’m writing this devfourm post because I’m currently having an issue with a script I want to create that allows a part to face a enemy player’s humanoidrootpart.

  2. My issue is that the script doesn’t work as intended where instead of facing the enemy player’s humanoidrootpart it just faces forwards and not where it’s intended to be.

  3. I’ve tried out bodygyro, attatchments, etc pretty much everything to try to recreate this but to no success.
    What I intend to happen:


    What I currently have:

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local function WeaponLookAt(Weapon, EnemyHumanoidRoot)
    local GunAttatchment = Instance.new("Attachment")
    local GunWeld = Weapon.Weld
    
    local EnemyLookAtAttatchment = Instance.new("Attachment")
    
    local GunPrimaryPart = Weapon.PrimaryPart
    
    local AlignWeaponOrientation = Instance.new("AlignOrientation")
    
    AlignWeaponOrientation.Parent = GunPrimaryPart
    
    AlignWeaponOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
    AlignWeaponOrientation.Responsiveness = 999
    --AlignWeaponOrientation.AlignType = Enum.AlignType.PrimaryAxisLookAt

    GunAttatchment.Parent = GunPrimaryPart
    EnemyLookAtAttatchment.Parent = EnemyHumanoidRoot
    
    AlignWeaponOrientation.Attachment0 = GunAttatchment
    
    
    AlignWeaponOrientation.CFrame = EnemyLookAtAttatchment.WorldCFrame
end

RemoteEvents.Gremmy.AddGuns.OnServerEvent:Connect(function(player)
    local GremmyFX = ReplicatedStorage.FX.Gremmy.Guns
    local Guns = GremmyFX:GetChildren()
    
    local Character = player.Character
    local HumanoidRootPart = player.Character.HumanoidRootPart
    local GunPositions = {
        Gun1 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(-2, -1.5, 0),
        Gun2 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(2, -1.5, 0),
        Gun3 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(0, -3.5, -2),
        Gun4 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(4, -.5, 2),
        Gun5 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(-2, -3.5, 2),
        Gun6 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(2.5, 2, 0),
        Gun7 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(-2, 2, 0),
        Gun8 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(2, -1.8, -2),
        Gun9 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(-4, -.5, 2),
        Gun10 = CFrame.new(HumanoidRootPart.CFrame.LookVector) * CFrame.new(-1, -3.9, -2)
    }
    local Enemy = FindNearestEnemy(Character)
    
    for i = 1, AmountOfGuns do
        task.wait(GunWait)
        local RandomGun = math.random(1, #Guns)
        local ChosenGun = Guns[RandomGun]:Clone()
        
        local WeldWeapon = Instance.new("Weld")
        
        
        ChosenGun.Parent = workspace.FX
        
        ChosenGun.PrimaryPart.CFrame = HumanoidRootPart.CFrame 
        
        WeldWeapon.Part0 = HumanoidRootPart
        WeldWeapon.Part1 = ChosenGun.PrimaryPart
        WeldWeapon.Parent = ChosenGun
        WeldWeapon.C1 = GunPositions["Gun"..i]
        
        GunClick(player.Character)
        
        
        RemoteEvents.Gremmy.AddGuns:FireAllClients(WeldWeapon)
    
        WeaponLookAt(ChosenGun, Enemy)    
    end        
end)

Have you tried using CFrame.lookAt?
i.e
AlignWeaponOrientation.CFrame = CFrame.lookAt(GunPrimaryPart.Position, EnemyHumanoidRoot.Position)

Yes I have it gives me this odd behavior and doesn’t stay locked onto the enemy player