Lua 尝试在FiveM essentialmode上索引nil值(字段';?';)

Lua 尝试在FiveM essentialmode上索引nil值(字段';?';),lua,Lua,我在代码的一部分有问题,我不是编码员,我在互联网上查看了一下,但没有找到任何有用的东西,问题出现在第234行,这是if groups[Users[source].getGroup()]:canTarget(group)thenidk怎么办,这是错误 运行resource essentialmode:citizen的调用引用函数时出错:/scripting/lua/scheduler.lua:351:server/main.lua:234:尝试索引nil值(字段“?”) 堆栈回溯: server/

我在代码的一部分有问题,我不是编码员,我在互联网上查看了一下,但没有找到任何有用的东西,问题出现在第234行,这是
if groups[Users[source].getGroup()]:canTarget(group)then
idk怎么办,这是错误

运行resource essentialmode:citizen的调用引用函数时出错:/scripting/lua/scheduler.lua:351:server/main.lua:234:尝试索引nil值(字段“?”) 堆栈回溯: server/main.lua:234:在upvalue'ref'中 公民:/scripting/lua/scheduler.lua:337:函数内公民:/scripting/lua/scheduler.lua:336 [C] :在函数“xpcall”中 公民:/scripting/lua/scheduler.lua:336:函数内公民:/scripcfx-ting/lua/scheduler.lua:335> 堆栈回溯: [C] :在函数“error”中 公民:/scripting/lua/scheduler.lua:351:函数内公民:/scripting/lua/scheduler.lua:322

function addGroupCommand(command, group, callback, callbackfailed, suggestion)
commands[command] = {}
commands[command].perm = math.maxinteger
commands[command].group = group
commands[command].cmd = callback
commands[command].callbackfailed = callbackfailed

if suggestion then
    if not suggestion.params or not type(suggestion.params) == "table" then suggestion.params = {} end
    if not suggestion.help or not type(suggestion.help) == "string" then suggestion.help = "" end

    commandSuggestions[command] = suggestion
end

ExecuteCommand('add_ace group.' .. group .. ' command.' .. command .. ' allow')

RegisterCommand(command, function(source, args)
    if groups[Users[source].getGroup()]:canTarget(group) then
        callback(source, args, Users[source])
    else
        callbackfailed(source, args, Users[source])
    end
end)

debugMsg("Group command added: " .. command .. ", requires group: " .. group)          end

Lua只接受从1开始的索引,我通常在索引为0时得到这个错误。因此,您可以检查
source
Users[source].getGroup()
是否可能等于0确保它们总是
=1
有点晚,但为了将来其他登录到此处的用户提供参考:

当日志中出现错误时,如

citizen:/scripting/lua/scheduler.lua:351:server/main.lua:234:尝试索引nil值(字段“?”)

这往往是因为从数据库中获取的数据是空的

比如说,

Error running call reference function for resource esx_identity: citizen:/scripting/lua/scheduler.lua:405: @esx_identity/server/main.lua:11: attempt to index a nil value (field '?')
stack traceback:
@esx_identity/server/main.lua:11: in upvalue 'ref'
esx_identity/server/main.lua
中的第11行是:

如果结果[1].firstname~=nil,则

引用的
firstname
是从数据库返回的空值。SQL查询通常非常接近问题代码行


检查数据库中是否有包含空值的行,并删除或修复任何存在的行。

为什么数组
用户
以大写字母开头,而数组
不以大写字母开头?是否正确?也许
用户[GetPlayerName(source)]
会更正确?