How can i assign a certain function to a button?

Do you mean a UI button or a keyboard/gamepad button?

UI button. But i decided to get that out of my project. Can you help me with picking up an item and attaching it to a socket please?

What im trying to do is to make a random item appear when the player presses a button. I used a tutorial on random item spawner to get random items and now i want to make them appear only when the button is pressed. And one more thing i wanted to do is that after the item spawns, the player has to pick it up and put it in a socket, like a puzzle until all the items are in the correct sockets. Pls halp.