Skip to content

Commit

Permalink
Mitigate error if metadata is not valid (disconnected player) (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
S-S-X authored Oct 12, 2021
1 parent 9fa18c5 commit 1a6e893
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ end

local function set_player_attribute(player, key, value)
if player.get_meta then
if value == nil then
player:get_meta():set_string(key, "")
else
player:get_meta():set_string(key, tostring(value))
local meta = player:get_meta()
if meta and value == nil then
meta:set_string(key, "")
elseif meta then
meta:set_string(key, tostring(value))
end
else
player:set_attribute(key, value)
Expand All @@ -78,7 +79,8 @@ end

local function get_player_attribute(player, key)
if player.get_meta then
return player:get_meta():get_string(key)
local meta = player:get_meta()
return meta and meta:get_string(key) or ""
else
return player:get_attribute(key)
end
Expand Down

0 comments on commit 1a6e893

Please sign in to comment.