In addition to what the other answers have pointed out, maybe I'll add this, which I think may be the main point of confusion:
A rope is a "physical", massive object comprised of segments/atoms that each have a certain position at any moment in time.* On the other hand, electromagnetic waves are states of the electromagnetic field, which is everywhere and has a specified magnitude and direction at each point in space(-time).
In more detail:
If a rope oscillates, that means that the actual masses which comprise it are moving in one direction or the other. If the rope begins at some position $(x_0, y_0, z_0)$, ends at some position $(x_0, y_0, z_0+L)$ and is oscillating in the $x$ direction, then the rope segment at some "height" $y_0, z$ at time $t$ might be at a position $x = x_0 + A\sin\left(\frac{n\pi z}{L}\right) \sin(\omega t)$ for some $A$, $n$ and $\omega$. In particular, it makes no sense to ask what the position of the rope is at some $y \neq y_0$: The rope simply doesn't exist there.
Now, more pertinent to the question at hand is actually the following: Each piece of the rope has a position, but that's it. A rope doesn't have anything else attached to it; it is a collection of particles (and thus it is essentially describable by purely mechanical theory).
On the other hand, the electromagnetic field $\vec{E}(x,y,z,t)$ is a vector field. There are two main distinctions to the rope case:
- The field exists at every point $(x,y,z)$ in space, as mentioned above (hence, instead of mechanics we use what is called field theory to describe such settings).
- At every point in space, there is a vector $\vec{E}$ pointing in some direction with some magnitude. That is to say, at every point in space, there is a vector pointing somewhere, and the vector at $(x,y,z,t)$ is the electromagnetic field at $(x,y,z,t)$. Hence the collection of all of the vectors at all points in spacetime is called a vector field.
The first point means it now makes sense to ask about the EM field at any point in space, as there will be some definite $\vec{E}$ for any point and any time. The second point is what answers the question in my opinion: When we say an EM wave is oscillating, we do not mean that there is some collection of masses or even massless objects** oscillating, but simply that the direction in which the vector $\vec{E}$ is pointing oscillates.
That means that when we say an electromagnetic wave oscillates transversely to its direction of propagation, there is no "rope" moving back and forth, but simply that the direction in which the vector at each position is pointing is moving back and forth.
Extending the example from above to the EM case, we might consider an electromagnetic standing wave of (angular) frequency $\omega$ that is fully polarized in the $x$ direction.*** Then the $\vec{E}$ field at the position $(x_0, y_0, z)$ would be
$$\vec{E}(x_0, y_0, z, t) = E_0 \sin\left(\frac{n\pi z}{L}\right) \sin(\omega t) \begin{pmatrix}1\\0\\0 \end{pmatrix},$$
where $E_0$ is the amplitude (compare to $A$ above) and $n \pi / L \overset{!}{=} \omega/c$ with $c$ the speed of light (the same would hold true for the appropriate speed above).
Note that, crucially, the thing that is oscillating here is not "the EM field itself" in the sense that the rope was oscillating, but just the vector that constitutes the EM field. Note also that the oscillation direction $x$ is transverse to (what is effectively) the direction of propagation $z$, as you mentioned.
Note also that since we assumed a planar wave in the $z$ direction, it doesn't matter if we consider $x_0, y_0$ or any other $x, y$, since the field does exist at those arbitrary other points and is by the planar-wave assumption exactly equal to the value at $x_0, y_0$.
In other words, one could think of the EM wave as a set of rays—or straight lines!—in the $z$ direction, as you mentioned, and the $x$ component of the vector at each point in these rays is what is oscillating, not "the ray" itself.
It is in this sense that EM waves travel both in straight lines while simultaneously oscillating in the transverse direction.
*at least classically, but let's not bother with unnecessary complications here
**Well, if you get into quantum field theory, you could argue about the interpretation of the harmonic oscillators underlying the quantized EM field, but I don't think that's a meaningful discussion to have here.
***I chose a standing wave to make the rope analogy clearer (how would an oscillating rope travel?). The argument works exactly the same for a traveling wave.