Firstly, use :Connect
not :connect
. The latter is deprecated and may stop working at any point.
Secondly, as the error clearly states, you are attempting to index something for your variable 'player' which hasn't been defined. This can be troubleshooted by going through your code and looking at all the places you use your 'player' variable, then see if the player has been defined at that point.
Going through your code, the 'player' variable is indeed NOT defined for your functions because they all take in the 'player' parameter but that variable is not passed when you actually call the functions here:
and here:
1 | game.Players.PlayerRemoving:connect(saveDataForPlayer()) |
To fix this, simply put the 'player' variable in the parenthesis so that you pass that variable to your functions.