I posted a previous question about my datastore and was recommended to migrate over to datastore2, but it's not saving and I'm not sure why, this is first time using datastore2 so don't trash me on my code, I kinda got the gist of what to do from a devforum article.
local DataStore2 = require(1936396537)
local leaderstats1 = {
["Level"] = 0,
["XP"] = 0,
["MaxHealth"] = 120,
["Qalium"] = 0,
["HealthP"] = 0,
["SwordP"] = 0,
["MeleeP"] = 0,
["ClassP"] = 0,
["Points"] = 0,
["Tries"] = 10,
}
local leaderstats2 = {
["Element"] = "",
["Sign"] = "",
}
DataStore2.Combine("MasterKey","Qalus")
local function savedata(folder)
local tab = {}
for i,v in pairs(folder:GetChildren()) do
tab[v.Name]= v.Value
end
return tab
end
game.Players.PlayerAdded:Connect(function(plr)
local datastore = DataStore2("Data",plr)
local folder = Instance.new("Folder", plr) folder.Name = "leaderstats1"
for i,v in pairs(leaderstats1) do
local intval = Instance.new("NumberValue",folder)
intval.Name = i
intval.Value = v
end
for i,v in pairs(leaderstats2) do
local intval2 = Instance.new("StringValue",folder)
intval2.Name = i
intval2.Value = v
end
local data = datastore:Get()
if data ~= nil then
for i,v in pairs(data) do
if folder:FindFirstChild(i) then
folder[i].Value = v
end
end
end
for i,v in pairs(folder:GetChildren()) do
v.Changed:connect(function()
local tab = savedata(folder)
datastore:Set(tab)
end)
end
end)
