It's similar to a VIP door but I'm terrible at player stuff except for GUIs. Can you give me code? like: (except actual working LUA)

texture="hat texture"
if player has the hat texture then give <tool>

also I want it so that if they drop the hats, they lose the tools associated with the hat, and if they pick it up again they regain it. This sounds totally annoying to do, and I have no clue how to do it. Seems similar to a VIP door except there are a few major differences. Please don't answer if you won't give me a full answer. I really appreciate it! Thanks :D