Find your hat challenge

Hey hope you are all having a fantastic day, this is my version of the challenge game “Find your hat” , since i have seen some people having some hard time trying to understand it i did my best to make it easy to understand and keep the script short.
please feel free to give me your feedbacks.