I was attempting to remove a player from my multiplayer game using the /admin command, as he had soft-locked himself on a different planet. However, when doing so, I encountered an error:
__rubia__/script/chunk-checker.lua:265: attempt to index local 'player' (a nil value)
stack traceback:
__rubia__/script/chunck_checker.lua:265: in function 'try_update_player_pos'
__rubia__/script/chunck_checker.lua:341: in function 'fun'
__rubia__/lib/event-lib.lua:77: in function <__rubia__/lib/event-lib.lua:75>
Analysis:
The core of the problem is in __rubia__/script/chunck_checker.lua:335
and __rubia__/script/chunck_checker.lua:340
. On line 335, you're registering the function to be called in on_player_removed, which happens after the player is removed. Then, on line 340, you attempt to get the player from the player_index
of the player that was just removed. game.get_player
will then return nil, so on line 341 you erroneously call try_update_player_pos
, which expects an existing player. To fix the problem, you should change line 335 to defines.events.on_pre_player_removed
which will allow you to access the LuaPlayer
before it is deleted.