Pathfinding teleporting zombies

I want to make the zombie go to the player and at 50 it will just stop.
However,My zombie just teleports.

local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local humanoid = script.Parent:WaitForChild("Humanoid")
local Torso = script.Parent:WaitForChild("HumanoidRootPart")
local zombie = script.Parent
local Range = 500
local shootDis = 50

RunService.Heartbeat:Connect(function(dl)
	for i, player in pairs(Players:GetPlayers()) do
		local distance = (player.Character.PrimaryPart.Position - Torso.Position).Magnitude
		if distance < Range then
			local Path = PathfindingService:CreatePath(
				{AgentRadius = 2,
					AgentHeight = 5,
					AgentCanJump = true,
					AgentCanClimb = true,
					WaypointSpacing = 4})
			Path:ComputeAsync(Torso.Position, player.Character.PrimaryPart.Position)
			local Waypoints = Path:GetWaypoints()
			if Path.Status == Enum.PathStatus.Success then
				for i, waypoint in pairs(Waypoints) do
					humanoid:MoveTo(waypoint.Position)
				end
			end
			if distance < shootDis then
				humanoid:ChangeState(Enum.HumanoidStateType.PlatformStanding)
				Torso.Anchored = true
				wait(1)
				Torso.Anchored = false
				humanoid:ChangeState(Enum.HumanoidStateType.Running)
			end

		end
	end
end)

You should use the Humanoid.MoveToFinished event to wait until the zombie reaches a waypoint before moving to the next one.

if Path.Status == Enum.PathStatus.Success then
    for i, waypoint in pairs(Waypoints) do
        humanoid:MoveTo(waypoint.Position)
        humanoid.MoveToFinished:Wait()

        local currentDistance = (player.Character.PrimaryPart.Position - Torso.Position).Magnitude
        if currentDistance < shootDis then
            -- Perform actions when within shooting distance
            break 
        end
    end
end

if i do that it will make it move very weirdly like moving left and right even thought the player is right in front of them