Here is a clip of how it doesn’t work.
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SavedData")
Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new("Folder", player)
Stats.Name = "leaderstats"
local Stage = Instance.new("StringValue", Stats)
Stage.Name = "Stage"
Stage.Value = 1
local Data = SaveDataStore:GetAsync(player.UserId)
if Data then
for i, stats in pairs(Stats:GetChildren()) do
stats.Value = Data[stats.Name]
end
end
player.CharacterAdded:Connect(function(character)
local Humanoid = character:WaitForChild("Humanoid")
local Root = character:WaitForChild("HumanoidRootPart")
if Root and Humanoid then
if Stage.Value ~= 0 then
local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
Root.CFrame = StagePart.CFrame + Vector3.new(0,5,0)
end
end
end)
end)
local function SavePlayerData(player)
local success, errormsg = pcall(function()
local SaveData = {}
for i, stats in pairs(player.leaderstats:GetChildren()) do
SaveData[stats.Name] = stats.Value
end
SaveDataStore:SetAsync(player.UserId,SaveData)
end)
if errormsg then
warn(errormsg, script)
end
end
Players.PlayerRemoving:Connect(function(player)
SavePlayerData(player)
end)
game:BindToClose(function()
for i, player in pairs(Players:GetPlayers()) do
SavePlayerData(player)
end
end)
this is the code that supposed to teleport you to the checkpoint but it doesn’t work, I fall out of the sky