Checking value from firebase and indexing

I am creating like a queueing system so I need to make the index inorder from the firebase db. I want first to check from the firebase if this current queue number is taken then the current num will be indexed to +1 =2 then it goes on until the value and the current num is not equal. Do you have any block suggestions? ![:face_with_crossed_out_eyes:|16x16]


blocks progress


firebase db