Reputation: 15
I'm trying to make a DB, still in testing phrase, but: As you can see, it's basically unpacking a table gives us "nil".
It's a strange error I've not been able to fix.
Testing ServerScriptService Script:
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)
Module Scirpt:
--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
Thanks in advance.
Upvotes: 0
Views: 113
Reputation: 28950
save_key
is a the same table as new
save_key = unpack(save_key)
assings nil
to save_key
unpack(save_key)
returns nil
as save_key
is not a sequence.
unpack (list [, i [, j]])
is equivalent to return list[i], list[i+1],..,list[j]
where
i
and j
default to 1
and #list
The only field in new
is new["Set"]
.
Upvotes: 1