Hello, Ive been working on my datastore and i keep getting this " attempt to call a table value]"
when trying to edit Inv Data, but editing Stats Data works completely fine… Im not sure whats going wrong here
calling it like this works
local DataStore = require(game.ServerScriptService.MainServerScript.Modules.DataHandler) DataStore.EditData(plr,"Points",2,true,false)
But calling it like this
local DataStore = require(game.ServerScriptService.MainServerScript.Modules.DataHandler) DataStore.EditData(plr,"LastLogin","158592686",false,true)
doesnt work
Here is the complete code if you want to check it out yourself
local Main = {}
local g = game
local Players = g.Players
local LocalPlayer = Players.LocalPlayer
--DataStore Start
local DataStore = require(script.DataStore2)
local Key = "wjdiaw2242"
DataStore.Combine(Key, "Stats1","Stats2","Inv1","Inv2","Pets")
-----------------
--Main DataStore Fucntion
local function SetDataTable()
local UserData = {
Stats1 = {
["Points"] = 0,
["Tokens"] = 0,
},
Stats2 = {
["Points"] = 0,
["Tokens"] = 0,
},
Inv1 = {
["HitSpeed"] = 1,
["HitTick"] = 1,
["HitFinishValue"] = 50,
["Supplies"] = 2,
["BackPack"] = 2,
["LastLogin"] = os.time(),
["DaysInARow"] = 0,
},
Inv2 = {
["HitSpeed"] = 1,
["HitTick"] = 1,
["HitFinishValue"] = 50,
["Supplies"] = 2,
["BackPack"] = 2,
["LastLogin"] = os.time(),
["DaysInARow"] = 0,
},
--PlaceHolder
Pets = {
},
}
return UserData
end
------------------------
--Init
local function Init_1(arg_1)
print("[SERVER] DataHandler Started")
Players.PlayerAdded:Connect(function(player)
local UserData = DataStore(Key,player):Get(SetDataTable())
--Public Data
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue",leaderstats)
Points.Name = "Points"
local Tokens = Instance.new("IntValue",leaderstats)
Tokens.Name = "Coins"
--Hidden Data
local PerFolder = Instance.new("Folder")
PerFolder.Name = "PerFolder"
local HitSpeed = Instance.new("IntValue",PerFolder)
HitSpeed.Name = "HitSpeed"
local HitTick = Instance.new("IntValue",PerFolder)
HitTick.Name = "HitTick"
local HitFinishValue = Instance.new("IntValue",PerFolder)
HitFinishValue.Name = "HitFinishValue"
local Supplies = Instance.new("IntValue",PerFolder)
Supplies.Name = "Supplies"
local BackPack = Instance.new("IntValue",PerFolder)
BackPack.Name = "BackPack"
local LastLogin = Instance.new("IntValue",PerFolder)
LastLogin.Name = "LastLogin"
local DaysInARow = Instance.new("IntValue",PerFolder)
DaysInARow.Name = "DaysInARow"
repeat wait() until player.Team ~= game.Teams.Choosing
local what
if player.Team == game.Teams.Infected then
what = 1
else
what = 2
end
local StatsData = DataStore("Stats"..what,player)
local InventoryData = DataStore("Inv"..what,player)
local Pets = DataStore("Pets",player)
local function UpdateStats(UpVal)
Points.Value = StatsData:Get(UpVal).Points
Tokens.Value = StatsData:Get(UpVal).Tokens
end
local function UpdateInv(UpVal)
HitSpeed.Value = InventoryData:Get(UpVal).HitSpeed
HitTick.Value = InventoryData:Get(UpVal).HitTick
HitFinishValue.Value = InventoryData:Get(UpVal).HitFinishValue
Supplies.Value = InventoryData:Get(UpVal).Supplies
BackPack.Value = InventoryData:Get(UpVal).BackPack
LastLogin.Value = InventoryData:Get(UpVal).LastLogin
DaysInARow.Value = InventoryData:Get(UpVal).DaysInARow
end
UpdateStats(UserData["Stats"..what])
UpdateInv(UserData["Inv"..what])
StatsData:OnUpdate(UpdateStats)
InventoryData:OnUpdate(UserData)
leaderstats.Parent = player
PerFolder.Parent = player
end)
end
------
--EditData
local function EditData(plr,data,value,stats,set)
repeat wait() until plr.Team ~= game.Teams.Choosing
local what
if plr.Team == game.Teams.Infected then
what = 1
else
what = 2
end
local UserData = DataStore(Key,plr):Get(SetDataTable())
local StatsData = DataStore("Stats"..what,plr)
local InventoryData = DataStore("Inv"..what,plr)
local Pets = DataStore("Pets",plr)
if stats then
if set then
UserData["Stats"..what][data] = value
else
UserData["Stats"..what][data] = UserData["Stats"..what][data] + value
end
StatsData:Set(UserData["Stats"..what])
else
if set then
UserData["Inv"..what][data] = value
else
UserData["Inv"..what][data] = UserData["Inv"..what][data] + value
end
InventoryData:Set(UserData["Inv"..what])
end
end
---------
Main.Init = Init_1
Main.EditData = EditData
return Main
Thank you for your time!