Recently I made a Datastore script which works fine, except that it doesn't save the leaderstat called 'level'
local Data = game:GetService("DataStoreService")
local Points = Data:GetDataStore("poop")
local Levels = Data:GetDataStore("peep")
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder", plr)
stats.Name = "leaderstats"
local points = Instance.new("IntValue", stats)
points.Name = "Points"
local lvl = Instance.new("IntValue", stats)
lvl.Name = "Level"
local DSS
local LSS
local success, errormessage = pcall(function()
DSS = Points:GetAsync(plr.UserId.."-points")
LSS = Levels:GetAsync(plr.UserId.."-lvls")
end)
if success then
warn("Successfully loaded " ..plr.Name.."'s data!")
points.Value = DSS
lvl.Value = LSS
else
warn("There was an error getting "..plr.Name.."'s data! Here's why")
error(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall (function()
Points:SetAsync(plr.UserId.."-points", plr.leaderstats.Points.Value)
Levels:SetAsync(plr.UserId.."-lvls", plr.leaderstats.Level.Value)
end)
if success then
warn("Successfully saved "..plr.Name.."'s data!")
else
warn("There was an error saving "..plr.Name.."'s data! Here's why:")
error(errormessage)
end
end)
I've tried many things to maybe fix it but nothing seems to really work. I would appreciate it if someone could help.
