【发布时间】:2021-09-30 14:44:21
【问题描述】:
我正在尝试创建一个数据库,但仍处于测试阶段,但是: 正如你所看到的,它基本上是拆表给我们“nil”。
这是一个我无法修复的奇怪错误。
测试 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)
模块脚本:
--Variables
local dss = game:GetService("DataStoreService")
local db = dss:GetDataStore("greenwich")
-- Tables
local greenwich = {}
local dbFunctions = {}
--Functions
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
--Returning everything.
return greenwich
提前致谢。
【问题讨论】: