Mob in front of you

Workspace.Mob.HumanoidScript:32: attempt to index local ‘target’ (a nil value)

Also “Enemy” is Humanoid and Humanoid doesn’t got Position.

I see I overlooked some errors, how can one get the position of the mob?

Did you try increasing the compared number when this happened?

Was that not the goal? Nvm didn’t read thoroughly

while wait(0.1) do
    local target = findNearestTorso(script.Parent.HumanoidRootPart.CFrame.p)
    if target ~= nil and (target.CFrame.p - script.Parent.HumanoidRootPart.CFrame.p).magnitude > 5 then
        Enemy:MoveTo(target.CFrame.p, target)
    else
        Enemy.WalkToPoint = script.Parent.HumanoidRootPart.CFrame.p
    end
end

For some reason, mob is going sometimes left near me and starts going left- right, left-right in one place.

Might be because of the WalkToPoint, I wasn’t sure how to stop MoveTo() correctly.

Try this:

while wait(0.1) do
    local target = findNearestTorso(script.Parent.HumanoidRootPart.CFrame.p)
    if target ~= nil and (target.CFrame.p - script.Parent.HumanoidRootPart.CFrame.p).magnitude > 5 then
        Enemy:MoveTo(target.CFrame.p, target)
    else
        Enemy:MoveTo(script.Parent.HumanoidRootPart.CFrame.p, script.Parent.HumanoidRootPart)
    end
end
3 Likes

It worked! Thanks so much!

3 Likes