cant get off ladder

hi! so I put in code to make it possible for my character to go on a ladder and go up and down, but when I get on it, I can go as high as I want even though the character isnt touching the ladder object anymore. also, i cant move left or right on the ladder, or even jump off of the ladder, so the moment i touch the ladder im stuck there forever..

heres my code:


if (key_up || key_down)
if place_meeting(x,y,obj_ladder) ladder = true

if (obj_ladder)
x = (instance_nearest (x,y,obj_ladder).x)
vsp = 0
grav = 0
if (key_up) vsp = -2
if (key_down) vsp = 2
if !place_meeting(x,y,obj_ladder) ladder = false
if (key_jump) ladder = false

else {
ladder = false
grav = 0.5
sorry if its a simple error, i just dont know how to fix it :/