local dataStoreService = game:GetService("DataStoreService")
local StageStore = dataStoreService:GetDataStore("PlayersDataStore")
function PlrToStage(plr)
repeat wait() until plr.Character.HumanoidRootPart
local stagePart = game.Workspace.Checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
plr.Character.HumanoidRootPart.CFrame = stagePart.CFrame + Vector3.new(0,2.5,0)
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = leaderstats
local sucess, errormessage = pcall(function()
stage.Value = StageStore:GetAsync(player.UserId)
end)
if sucess then
print("Sucessfully Got"..player.Name"'Stage Data.")
else
warn(errormessage)
end
if player.Character then
PlrToStage(player)
end
player.CharacterAdded:Connect(function()
PlrToStage(player)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local sucess, errormessage = pcall(function()
StageStore:SetAsync(player.UserId,player.leaderstats.Stage.Value)
end)
if sucess then
print("Sucessfully Saved"..player.Name"Stage Data.")
else
warn(errormessage)
end
end)
for _, checkpoint in pairs (game.Workspace.Checkpoints:GetChildren()) do
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FIndFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checkpointNumber = tonumber(checkpoint.Name)
if player.leaderstats.Stage.Value < checkpointNumber then
player.leaderstats.Stage.Value = checkpointNumber
end
end
end)
end
check if you have API services enabled