How do I assign slots to gamepads for a local multiplayer game?

Hello!

I want to add another gamepad controller, up to 4 total, to my game, with each person controlling their own character. I want to start off with a UI that shows what controllers are connected, and to what slot they are attached to. How would I make it so that the game assigns a gamepad to a Controller ID after a button has been pressed on that gamepad? I.e. with 4 controllers connected, one controller presses the A button and is assigned the slot for player 0. So on and so forth.

Thanks in advance!