ROBLOX LUA(u) 尝试在数据库上调用 nil 值
ROBLOX LUA(u) Attempt to call a nil value on Database
我正在尝试制作数据库,但我仍处于测试阶段,但它不起作用。
基本上错误是,我想要它,所以如果我键入:ModuleScript:GetDB("salvage").Set("key", "value")
,它会 return 一个值,但它不是由于错误。
非常感谢任何帮助。
错误:
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
提前致谢。
ModuleScript:GetDB("salvage")
returns new
没有字段 Set
所以你不能调用 ModuleScript:GetDB("salvage").Set("key", "value)
Set
是dbFunctions
的一个字段。您 运行 使用 ipairs
迭代器对其进行通用的 for 循环。 dbFunctions
不是序列,因此 ipairs
不适用于它。请改用 pairs
。
我正在尝试制作数据库,但我仍处于测试阶段,但它不起作用。
基本上错误是,我想要它,所以如果我键入:ModuleScript:GetDB("salvage").Set("key", "value")
,它会 return 一个值,但它不是由于错误。
非常感谢任何帮助。
错误: 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
提前致谢。
ModuleScript:GetDB("salvage")
returns new
没有字段 Set
所以你不能调用 ModuleScript:GetDB("salvage").Set("key", "value)
Set
是dbFunctions
的一个字段。您 运行 使用 ipairs
迭代器对其进行通用的 for 循环。 dbFunctions
不是序列,因此 ipairs
不适用于它。请改用 pairs
。