I’m trying to have an AI follow the player but stay behind by 10
It prints out that the player is Far enough away but doesn’t walk to the player.
I’m super confused!
Heres the script:
local function WalkTo(humanoid,destination,AI)
local path = Getpath(humanoid.Parent,destination)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
humanoid:MoveTo(waypoint.Position)
while true do
local distance = (AI.HumanoidRootPart.Position - waypoint.Position).Magnitude
local distance_From_Player = (AI.HumanoidRootPart.Position - game.Players:GetPlayers()[1].Character.HumanoidRootPart.Position).Magnitude
if distance > 5 then
break
end
if distance_From_Player < 10 then
humanoid:MoveTo(AI.HumanoidRootPart.CFrame*CFrame.new(0,0,-3).p)
print("Player Too Close")
break
else
print("Far Enough Away")
end
wait()
end
--humanoid.MoveToFinished:Wait()
end
else
--print("PathBlocked")
end
end
If you need more info ask!