Well, that I do not go for the loop with GetPlayers () I give debug and jump to the end and stop. I've tried a simple for loop and it works.
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players"):GetPlayers()
local enemy = script.Parent
local humanoidEnemy = enemy.Humanoid
local humanoidRootPart = enemy.HumanoidRootPart
local Start = script.Parent.Parent.Start
local Finish = script.Parent.Parent.Finish
local currentDestination = Start
for i , player in pairs(Players) do
local character = game.Workspace:WaitForChild(player.Name)
print(player.Name)
if character then
while wait(1) do
local mag = (character.Head.Position - enemy.Head.Position).magnitude
if mag <= 50 then
print("Attack")
else
print(mag)
while wait(2) do
local startingPosition = humanoidRootPart.Position
local goalPosition = currentDestination.Position
local path = PathfindingService:FindPathAsync(startingPosition, goalPosition)
local waypoints = path:GetWaypoints()
for waypointIndex, waypoint in pairs(waypoints) do
local waypointPosition = waypoint.Position
humanoidEnemy:MoveTo(waypointPosition)
humanoidEnemy.MoveToFinished:Wait()
end
if currentDestination == Start then
currentDestination = Finish
else
currentDestination = Start
end
end
end
end
end
end

2 comments
you need to use :GetChildren() because otherwise for example, it wouldn't know if you meant :GetDescendants or :GetChildren()
It does not work with any of those methods. Thank you