I am trying to make a checkpoint save when the player leaves and so when they join it teleports them back to the CFrame of the checkpoint, however I am having trouble identifying which checkpoint the player was last at.
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
--Don't worry about the rest of the code, except for line 25.
game.Players.PlayerAdded:connect(function(player)
local Stage = player.leaderstats.Stage
Stage.Value = ds:GetAsync(player.UserId)
ds:SetAsync(player.UserId, Stage.Value)
Stage.Changed:connect(function()
ds:SetAsync(player.UserId, Stage.Value)
end)
game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.CFrame = game.Workspace.Checkpoint(Stage.Value)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Stage.Value) --Change "Points" to the name of your leaderstat.
end)
How would I change game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.CFrame = game.Workspace.Checkpoint(Stage.Value)
to work? There are parts in the Workspace called Checkpoint1, Checkpoint2, Checkpoint3 etc…