--// DataStore2
local DataStore2 = require(script.DataStore2)
DataStore2.Combine("Xash","Death","Level")
--// Default Values
local DeathCount = 0
local XashCount = 10000
local LevelCount = 1
-- Metatable
local tab = {}
game.Players.PlayerAdded:Connect(function(plr)
local XashData = DataStore2("Xash", plr)
local DeathData = DataStore2("Death", plr)
local LevelData = DataStore2("Level", plr)
-- Metamethods
setmetatable(tab,{
__index = function(t,k)
local folder = Instance.new("Folder")
folder.Parent = plr
folder.Name = "leaderstats"
local Xash = Instance.new("IntValue")
Xash.Parent = folder
Xash.Name = "Xash"
local Level = Instance.new("IntValue")
Level.Parent = folder
Level.Name = "Level"
local Death = Instance.new("IntValue")
Death.Parent = folder
Death.Name = "Death"
return k
end
})
getmetatable(tab)
print("Indexing metamethod "..tab.t)
wait(.5)
local function saveDeath(update)
plr.leaderstats.Death.Value = DeathData:Get(update)
end
local function saveXash(update)
plr.leaderstats.Xash.Value = XashData:Get(update)
end
local function saveLevel(update)
plr.leaderstats.Level.Value = LevelData:Get(update)
end
saveXash(XashCount)
saveLevel(LevelCount)
saveDeath(DeathCount)
end)
What am i doing wrong, i get an error saying
[ServerScriptService.Script.DataStore2:368: attempt to index local ‘tableResult’ (a number value)