Check the last line. There is a variable named "player". You have to define that before giving as a parameter to a function. Add that code to top of your code.
Error running Lua task: [E745F7DC8279E46F] AttachToPlayer:1: Server script attempted to access a client-only field in a namespace. Field: Game.GetLocalPlayer
This can be only used in a client context. If you want to access it from a server script then you can broadcast from client to server or create a player joined event in server. Then you can use it.
You should probably move this post to #scripting-help instead of Lua snippets - Lua snippets is more intended to be for posts that teach something, not posts that ask something