I’m making a system using tables to store set and get DataStore v2 info.
Here’s my code:
local function UpdateVaultAmounts()
print("update ran")
local FakePerson = {UserId = 851048880, AncestryChanged = Instance.new("BindableEvent").Event, ClassName = "Player"}
print("update ran1")
local VaultMoneyTable = {}
local GARCoinStoreVault = DataStore2("GlobalBankAmounts", FakePerson)
print("update ran2")
VaultMoneyTable["RepublicStore"] = game.Lighting:FindFirstChild("VaultStorage"):FindFirstChild("RepublicVault").Value
VaultMoneyTable["ConfedStore"] = game.Lighting:FindFirstChild("VaultStorage"):FindFirstChild("ClanVault").Value
VaultMoneyTable["ClanStore"] = game.Lighting:FindFirstChild("VaultStorage"):FindFirstChild("ConfedVault").Value
print("update ran3")
GARCoinStoreVault:Set(VaultMoneyTable)
print("update ran4")
end
But when I use DataStore:Get(defaultTemplate) it only returns the default, or when I remove default, throws an error. Here’s my “Get” function:
local function SetUpVaults()
local FakePlayer = {UserId = 851048880, AncestryChanged = Instance.new("BindableEvent").Event, ClassName = "Player"}
local GARCoinStoreVault = DataStore2("GlobalBankAmounts", FakePlayer)
local VaultStorage = Instance.new("Folder")
VaultStorage.Parent = game.Lighting
VaultStorage.Name = "VaultStorage"
local RepublicVault = Instance.new("IntValue")
RepublicVault.Name = "RepublicVault"
RepublicVault.Parent = VaultStorage
local ConfedVault = Instance.new("IntValue")
ConfedVault.Name = "ConfedVault"
ConfedVault.Parent = VaultStorage
local ClanVault = Instance.new("IntValue")
ClanVault.Name = "ClanVault"
ClanVault.Parent = VaultStorage
local deftemplate = {
ClanStore = 100,
RepublicStore = 100,
ConfedStore = 101,
}
local Table = GARCoinStoreVault:Get(deftemplate)
ClanVault.Value = Table["ClanStore"]
RepublicVault.Value = Table["RepublicStore"]
ConfedVault.Value = Table["ConfedStore"]
end
The error it throws when no DefaultTable is present is "attempted to index nil with “ClanStore” in this line:
ClanVault.Value = Table["ClanStore"]
Can anyone help me?