while coroutine not ending correctly using unityscript

Hi I’m making a door open and close using a transform instead of animation

var speedTime : float;[1]
private var t: float = 0;

function Close() {
    
    	stateOpen = false;
    	stateClosing = true; // so we know its closing
    	while (t < speedTime) {
    		t += Time.deltaTime / speedTime; // sweeps from 0 to 1 in time seconds
    		transform.position = Vector3.Lerp(initialEnd, initialStart, t); // set position proportional to t
    		yield; // leave the routine and return here in the next frame
    	}
    
    	t = 0;
    	stateClosing = false; // so we know its not closing
    	stateClosed = true; // so we now its closed
    
    }

after closing the door i have to wait a prolonged ammount of time before i can open it again only if speedTime is over 1.
it seems as if the while coroutine is waiting the length of speedTime until allowing itself to play again.

any help would be great I’m really stumped

You actually don’t wait speedTime seconds but speedTime seconds squared

You divide Time.deltaTime by speedTime, so for example if speedTime is 5 it would take 5 seconds to reach 1.0. However your while condition checks for “t < speedTime”. So it doesn’t run 5 seconds but 25 seconds 5^2.

You want to use a while like this:

    while(t < 1.0f)