this is DataSaveScript
local DS = game:GetService("DataStoreService"):GetDataStore("CCSData")
game.Players.PlayerAdded:Connect(function(player)
wait()
local plr_key = "id_".. player.UserId
local saves = {
-- LEADERSTATS SAVES
player.leaderstats.Coins.Value,
player.leaderstats.Levels.Value,
--OTHER
player.TotalCoinsPickUp.Value,
player.TotalCoins.Value,
}
DS:SetAsync("id_"..player.UserId, saves)
local GetSaved = DS:GetAsync(plr_key)
if GetSaved then
for i, v in pairs(saves) do
v.Value = GetSaved[i]
end
else
local NFS = {}
for i, v in pairs(saves) do
table.insert(NFS, i, v.Value)
end
DS:SetAsync(plr_key, NFS)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
end)
and this is leaderstats script:
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local coins = Instance.new("NumberValue",stats)
coins.Name = "Coins"
coins.Value = 0
local totalcoins = Instance.new("IntValue", player)
totalcoins.Name = "TotalCoins"
totalcoins.Value = 0
local totalcoinspickup = Instance.new("IntValue",player)
totalcoinspickup.Name = "TotalCoinsPickUp"
totalcoinspickup.Value = 0
local level = Instance.new("IntValue", stats)
level.Name = "Level"
level.Value = 0