I am new to Godot and making a platformer. And to make the level exit I use a variable to change the scene but everytime the player beats level 2 they get sent back to level 2 without the variable changing
Your world variable is local so it likely gets reset and you are adding += 1 to the initial value again each time .change_scene() is called.
.change_scene()
So what would I need to change to the code?
You could use a Singleton to change your scene: https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html
The documentation even contains a tutorial on how to change scenes using a Singleton