Have you first searched what you require to complete this before posting a question? A lot of what you need to accomplish this can be found with some quick searches based on your needs at the time, such as how to create a TextButton click function. Spend a little more time searching.
As for the client-server mention, yes it is important. The client should be capturing the input and sending a request to the server via RemoteEvent that it wants to equip a hat. The server then holds the responsibility of performing checks where necessary, processing the request and handing over the hat if the request is deemed valid.
So, the thing is my text button connects to the handle of a tool/gear. Hats are different from gears, so let me look into hats. You could try your way first though.