Hey, so me and my friend are creating a difficulty chart and we’ve been stumped on how to make it so that when you rejoin the game after gaining some levels, you spawn back at the correct level. Currently we have a working checkpoint script and a working leaderstats script (with datastores) but we are trying to combine that with being able to rejoin at the correct checkpoint.
Scripts so far:
Leaderstats:
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = player.leaderstats
end)
Datastore:
game.Players.PlayerAdded:Connect(function(player)
wait(0.5)
local playerkey = "id_"..player.userId
local save = player.leaderstats.Stage
local GetSaved = ds:GetAsync(playerkey)
if GetSaved then
save.Value = GetSaved[1]
else
local numberforsaving = {save.Value}
ds:GetAsync(playerkey, numberforsaving)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync("id_"..player.userId, {player.leaderstats.Stage.Value})
end)
Checkpoint Scriipt #1:
spawn.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
if not checkpointData then
checkpointData = Instance.new("Model", game.ServerStorage)
checkpointData.Name = "CheckpointData"
end
local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
if not checkpoint then
checkpoint = Instance.new("ObjectValue", checkpointData)
checkpoint.Name = tostring(player.userId)
player.CharacterAdded:connect(function(character)
wait()
character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
end)
end
checkpoint.Value = spawn
end
end)
Checkpoint Script #2:
local Collected = {}
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
if Collected[Player.UserId] then return end
Collected[Player.UserId] = true
Player:WaitForChild("leaderstats").Stage.Value += 1
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
Collected[Player.UserId] = nil
end)
However we can incorporate the saving stage system, please let me know in the comments. Thanks once again!