Checking for the barrier and the train simultanously.