Hi, so I have a custom enemy I made that walks towards you and attack you but I can't seem to make it face towards me. Instead it faces towards the side. Please help
Script inside Enemy:
local enemy = script.Parent
local hrpOfenemy = enemy:WaitForChild("HumanoidRootPart")
local plrsHit = {}
local maxDistance = 100
local db = true
enemy.Head.Touched:Connect(function(h)
if h:IsA("BasePart") and h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= script.Parent.Name and db then
db = false
h.Parent.Humanoid:TakeDamage(20)
wait(1)
db = true
end
end)
while wait() do
local plrs = game.Players:GetPlayers()
local closestHRP
for i, plr in pairs(plrs) do
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") and plr.Character.Humanoid.Health > 0 then
local hrp = plr.Character.HumanoidRootPart
local distanceBetween = (hrpOfenemy.Position - hrp.Position).Magnitude
if not closestHRP then closestHRP = hrp end
if (hrpOfenemy.Position - closestHRP.Position).Magnitude < distanceBetween then
closestHRP = hrp
end
end
end
if closestHRP and (hrpOfenemy.Position - closestHRP.Position).Magnitude <= maxDistance then enemy.Humanoid:MoveTo(closestHRP.Position) end
end
Animation script:
local Humanoid = script.Parent.Humanoid
local runanim = Humanoid.RunAnim
local anim = Humanoid:LoadAnimation(runanim)
function onRunning(speed)
if speed > 0.01 then
anim:Play()
end
end
Humanoid.Running:Connect(onRunning)

5 comments
Sorry, I don't see how that would work since there only 2 things inside that new CFrame when there should be 3
U dont need to have 3 value in CFrame of BodyGyro, Try doing it like I wrote without multiplying with Cframe.Angles. If the enemy faces another way, then use Cframe.Angles
It says Argument 3 missing or nil
try removing CFrame.Angles line
Melodic don’t just take code