【问题标题】:ROBLOX LUA(u) Attempt to call a nil value on DatabaseROBLOX LUA(u) 尝试在数据库上调用 nil 值
【发布时间】:2021-09-29 23:47:11
【问题描述】:

我正在尝试创建数据库,但仍在测试阶段,但它不起作用。 基本上错误是,我想要它,所以如果我输入:ModuleScript:GetDB("salvage").Set("key", "value"),它会返回一个值,但不是因为错误。

非常感谢任何帮助。

错误: Photo

服务器脚本:

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)

模块脚本:

--Variables
local dss = game:GetService("DataStoreService")

-- Tables
local greenwich = {}
local dbFunctions = {}

--Functions
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

提前致谢。

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    ModuleScript:GetDB("salvage") 返回 new 没有字段 Set 所以你不能调用 ModuleScript:GetDB("salvage").Set("key", "value)

    SetdbFunctions 的字段。您使用 ipairs 迭代器对其运行通用 for 循环。 dbFunctions 不是一个序列,因此 ipairs 不适用于它。请改用pairs

    【讨论】:

      猜你喜欢
      • 2021-09-30
      • 2022-11-23
      • 1970-01-01
      • 2017-04-03
      • 2018-07-11
      • 2018-05-30
      • 2019-09-15
      • 2011-07-30
      • 2014-05-06
      相关资源
      最近更新 更多