what i'm trying to do is to save the players stats when they leave and load them back up when they join again
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("DeathSaveSystem")
local ds2 = datastore:GetDataStore("BrickSaveSystem")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bricks = Instance.new("IntValue")
bricks.Name = "Bricks"
bricks.Parent = leaderstats
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local humanoid = char:FindFirstChild("Humanoid")
humanoid.Died:Connect(function()
deaths.Value = deaths.Value + 1
end)
end)
bricks.Value = ds2:GetAsync(player.UserId) or 0
ds2:SetAsync(player.UserId, bricks.Value)
deaths.Value = ds1:GetAsync(player.UserId) or 0
ds1:SetAsync(player.UserId, deaths.Value)
game.Players.PlayerRemoving:Connect(function()
ds2:SetAsync(player.UserId, bricks.Value)
game.Players.PlayerRemoving:Connect(function()
ds1:SetAsync(player.UserId, deaths.Value)
end)
end)
end)

1 comment
(Not tested, i just write the code, idk if work)