it must follow the survivor and pathfind at the same time
however only turns when finished with the path
look at the vid closely
code
local function FindClosestSurvivorAndPathfindTo()
local closestSurvivor = nil
local closestSurvivorDistance = nil
local PathFindingService = game:GetService("PathfindingService")
for _, survivor in workspace.survivors:GetChildren() do
if survivor:FindFirstChild("HumanoidRootPart") and survivor:FindFirstChildOfClass("Humanoid").Health ~= 0 then
if closestSurvivor == nil then
closestSurvivor = survivor
closestSurvivorDistance = (script.Parent.HumanoidRootPart.Position - survivor.HumanoidRootPart.Position).Magnitude
else
local distance = (script.Parent.HumanoidRootPart.Position - survivor.HumanoidRootPart.Position).Magnitude
if distance < closestSurvivorDistance then
closestSurvivor = survivor
closestSurvivorDistance = distance
end
end
end
end
local path = PathFindingService:FindPathAsync(script.Parent.HumanoidRootPart.Position, closestSurvivor.HumanoidRootPart.Position)
local waypoints = path:GetWaypoints()
for i, point in waypoints do
local ball = Instance.new("Part")
ball.Anchored = true
ball.Color = Color3.new(1, 1, 1)
ball.Shape = Enum.PartType.Ball
ball.Material = Enum.Material.Neon
ball.Size = Vector3.new(0.5, 0.5, 0.5)
ball.CanCollide = false
ball.Position = point.Position
ball.Parent = workspace
game.Debris:AddItem(ball, 1)
script.Parent:FindFirstChildOfClass("Humanoid"):MoveTo(point.Position)
script.Parent:FindFirstChildOfClass("Humanoid").MoveToFinished:Wait()
end
end
while task.wait(0.25) do
FindClosestSurvivorAndPathfindTo()
end