ROBLOX LUA(u)传递表的参数= nil(尝试将 nil 与字符串连接)

我正在尝试制作一个数据库,还在测试阶段,但是: 如您所见,它基本上是解包一个表会给我们“nil”。

这是一个奇怪的错误,我无法修复。

Photo error

测试ServerScriptService脚本:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Greenwich = require(ServerStorage:WaitForChild("Greenwich"))

Players.PlayerAdded:Connect(function(Player)

    Player.Chatted:Connect(function(Message)

        if Message == "t" then

            local ServerName = script.Name
            print("T has been recognized by "..ServerName)

            print(Greenwich:GetDB("salvage"))
            warn(Greenwich:GetDB("salvage"):Set("MyKey", "MyValue"))

            print("Finalized.")

        end

    end)

end)

模块脚本:

--变量
local dss = game:GetService("DataStoreService")
local db = dss:GetDataStore("greenwich")

-- 表
local greenwich = {}
local dbFunctions = {}

--函数
function greenwich:GetDB(name)
    local new = {}
    coroutine.resume(coroutine.create(function()
        for k, v in pairs(dbFunctions) do
            new[k] = function(...)
                local args = { ... }
                return v(name, unpack(args))
            end
        end
    end))
    return new
end

function dbFunctions:Set(save_key, key, value)
    save_key = unpack(save_key)
    db:SetAsync(
        save_key..
            key,
        value)
    return value
end

-- 返回所有内容。
return greenwich

提前致谢。

点赞
用户2858170
用户2858170

save_keynew 表的同一个表格

save_key = unpack(save_key)nil 赋值给 save_key

由于 save_key 不是一个序列,所以 unpack(save_key) 返回 nil

unpack (list [, i [, j]]) 等价于 return list[i], list[i+1],..,list[j],其中 ij 默认值为 1#list

new 表只有一个字段,即 new["Set"]

注意:以上翻译保留了 markdown 的格式。

2021-07-23 14:41:28