It would help to tell people what language it’s in and for what engine or framework; you should also use a code block, because the forum made a mess of your code.