local player_data = storage.player_data[player.index]
if not player_data then
resmon.init_player(player) -- if this code path is triggered...
elseif not player.connected and player_data.current_site then
resmon.clear_current_site(player)
end
if player_data.current_site then -- this will crash
...
if player_data is nil, initialization is performed, but then player_data is never assigned to a non-nil value after, so an attempt is made to index nil.
The fix could be something like:
if player_data then
if player_data.current_site then
...
since both parts of the if/else assume player_data is accessible. Alternatively, player_data could be assigned after initialization:
if not player_data then
resmon.init_player(player)
player_data = storage.player_data[player.index]