code:
local Datastore = game:GetService("DataStoreService")
local data = Datastore:GetDataStore("data")
game.Players.PlayerAdded:Connect(function(player)
local leadstats = Instance.new("Folder")
leadstats.Name = "leaderstats"
leadstats.Parent = player
playerUserId = "Player_"..player.UserId
local checkpoints = Instance.new("IntValue")
checkpoints.Name = "Checkpoint"
checkpoints.Parent = leadstats
local chaptercompleted = Instance.new("IntValue")
chaptercompleted.Name = "completion"
chaptercompleted.Parent = leadstats
local load = Instance.new("IntValue")
local save
local success, errormsg = pcall(function()
save = data:GetAsync(playerUserId)
end)
if success then
checkpoints.Value = save
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormsg
success, errormsg = pcall(function()
local save = player.leaderstats.checkpoints.Value
data:SetAsync(playerUserId, save)
if success then
print("Data saved")
else
game.Players.LocalPlayer:WaitForChild("DebugScreen"):WaitForChild("DebugFrame").Visible = true
warn(errormsg)
end
end)
end)
it’s supposed to save the values so i can load it in the menu for checkpoint selections and checking if the player beat the chapter.