ROBLOX LUA(u)尝试对数据库调用空值的错误

我正在尝试制作一个数据库,并且仍处于测试阶段,但是它不起作用。 基本上出现的错误是,我希望如果我键入:ModuleScript:GetDB("salvage").Set("key", "value"),它将返回一个值,但由于出现错误,它不能返回任何值。

非常感谢任何帮助。

错误: 照片

服务器脚本:

local ModuleScript = require(game.ServerStorage.ModuleScript)

game.Players.PlayerAdded:Connect(function(p)
    p.Chatted:Connect(function(msg)
        if msg == "t" then
            print("lol")
            print(ModuleScript:GetDB("salvage"))
            ModuleScript:GetDB("salvage").Set("key", "value")
        end
    end)
end)

模块脚本:

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

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

-- 函数
function greenwich:GetDB(name)

    local db = dss:GetDataStore(name)
    local new = {}

    new.store = db

    coroutine.resume(coroutine.create(function()
        for k, v in ipairs(dbFunctions) do

            new[k] = function(...)

                local args = { ... }
                v(new.store, unpack(args))

            end

        end
    end))

    print(new.store.Name, name)

    return new

end

function dbFunctions:Set(store, key, value)
    print(value)
    return value
end

--Returning everything.
return greenwich

提前感谢。

点赞
用户2858170
用户2858170
`ModuleScript:GetDB("salvage")` 返回 `new`,它没有 `Set` 字段,所以无法调用 `ModuleScript:GetDB("salvage").Set("key", "value")`。

`Set` 是 `dbFunctions` 的一个字段。您可以使用 `ipairs` 迭代器对其进行通用的for循环。`dbFunctions` 不是序列,因此 `ipairs` 对其不起作用。请改用 `pairs`。
2021-07-22 17:54:47