--var local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("MoneyData") local ds2 = datastore:GetDataStore("LevelData") local ds3 = datastore:GetDataStore("RebirthData")
local cooldown = 60
--work game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = leaderstats
local level = Instance.new("IntValue")
level.Name = "Level"
level.Parent = leaderstats
local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
local moneyData -- money
local successMoney, errorMoney = pcall(function()
moneyData = ds1:GetAsync(plr.UserId.." _money")
end)
local levelData -- level
local successLevel, errorLevel = pcall(function()
levelData = ds2:GetAsync(plr.UserId.." _level")
end)
local rebData -- rebirths
local successReb, errorReb = pcall(function()
rebData = ds3:GetAsync(plr.UserId.." _rebirths")
end)
if successMoney then
money.Value = moneyData
else
print("We couldnt store the money")
warn(errorMoney)
end
if successLevel then
level.Value = levelData
else
print("We couldnt store the level")
warn(errorLevel)
end
if successReb then
rebirths.Value = rebData
else
print("We couldnt store the reborths")
warn(errorReb)
end
while wait(cooldown) do
ds1:SetAsync(plr.UserId.." _money", money.Value)
ds2:SetAsync(plr.UserId.." _level", level.Value)
ds3:SetAsync(plr.UserId.." _rebirths", rebirths.Value)
print("Data autosaved")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local successMoney, errorMoney = pcall(function()
ds1:SetAsync(plr.UserId.." _money", plr.leaderstats.Money.Value)
end)
local successLevel, errorLevel = pcall(function()
ds2:SetAsync(plr.UserId.." _level", plr.leaderstats.Level.Value)
end)
local successReb, errorReb = pcall(function()
ds3:SetAsync(plr.UserId.." _rebirths", plr.leaderstats.Rebirths.Value)
end)
if successMoney then
print("money data stored successfully")
else
print("We couldnt store the money")
warn(errorMoney)
end
if successLevel then
print("level data stored successfully")
else
print("We couldnt store the level")
warn(errorLevel)
end
if successReb then
print("rebirths data stored successfully")
else
print("We couldnt store the rebirths")
warn(errorReb)
end
end)

5 comments
whoops the code is inside "game.Players.PlayerAdded:Connect(function(plr)" and "end)"
There is no code there for saving/loading an data. All you are doing is creating leaderboard stats
yea i have many other scripts for saving leaderboards but none of them work. Can someone edit this code so that it works pls. Also could someone explain it pls??
ok to be honest, i souldnt have been so lazy, i will edit this question and will put the code which i tried to save the leaderboards
whoops the code i put here is messed up