local Stats = {"Stat1","Stat2","Stat3","Stat4","Stat5"
,"Stat6","Stat7","Stat8","Stat9","Stat10"}
local function Create(User)
local StatsFolder = Instance.new("Folder",User)
StatsFolder.Name = "leaderstats"
for i = 1,#Stats do
Instance.new("IntValue",StatsFolder).Name = Stats[i]
end
end
game.Players.PlayerAdded:connect(function(Player)
Create(Player)
end)
This script creates the stats
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
game.Players.PlayerRemoving:connect(function(Player)
Player:WaitForDataReady()
local Stats = Player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #Stats do
DataStore:SetAsync(Stats[i].Name,Stats[i].Value)
end
end)
game.Players.PlayerAdded:connect(function(Player)
Player:WaitForDataReady()
local Stats2 = Player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #Stats2 do
Stats2[i].Value = DataStore:GetAsync(Stats2[i].Name)
end
end)
This script saves the stats
I don't want my players to work hard and then lose all their data when they leave, is this system likely to fail?

2 comments
I highly recommend this video https://www.youtube.com/watch?v=tOOS9lMIYes
Thank you for sharing this video