From 150ec165fcd92c5815d952fdf9d67ffdbf9ee625 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 21 Nov 2021 17:26:29 +1100 Subject: [PATCH] fix(server): clone and wipe the playerlist when restarting the resource Since we're looping through the table, we end up trying to index new values as they are added. --- server/main.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/main.lua b/server/main.lua index f411692..5becd5c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -40,7 +40,9 @@ elseif ESX.GetConfig().Multichar == true then end if next(ESX.Players) then - for k, v in pairs(ESX.Players) do + local players = table.clone(ESX.Players) + table.wipe(ESX.Players) + for _, v in pairs(players) do ESX.Players[GetIdentifier(v.source)] = true end else ESX.Players = {} end @@ -48,9 +50,9 @@ elseif ESX.GetConfig().Multichar == true then local function SetupCharacters(source) while not FETCH do Citizen.Wait(100) end local identifier = GetIdentifier(source) - ESX.Players[identifier] = true + ESX.Players[identifier] = true - local slots = MySQL.Sync.fetchScalar("SELECT slots FROM multicharacter_slots WHERE identifier = ?", { + local slots = MySQL.Sync.fetchScalar("SELECT slots FROM multicharacter_slots WHERE identifier = ?", { identifier }) or SLOTS identifier = PREFIX..'%:'..identifier