Hello!
I have an Obby that works great, my Leaderboard keeps track of which Stage you are on and saves the data perfectly.
However; when I rejoin my server, My character respawns at the start spawn instead of the last spawn they touched. The leaderboard will say I am currently on Stage 9, but spawns be on Stage 1.
How can I incorporate a lookup script that would teleport the player to the last touched spawn?
This is in Workspace:
function oa(object)
local player = game.Players:playerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
print("gah")
object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
wait()
object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end end
function oe(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
ack.Parent = object
end end
game.Players.ChildAdded:Connect(oe)
game.Workspace.ChildAdded:Connect(oa)
And this is located inside of my checkpoints:
function ot(hit)
if hit.Parent ~= nil then
local player = game.Players:playerFromCharacter(hit.Parent)
if player ~= nil then
if player.leaderstats.Stage.Value == script.Parent.Name - 1 then
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.Health ~= 0 then
player.leaderstats.Stage.Value = script.Parent.Name
end end end end end end
script.Parent.Touched:Connect(ot)
local spawn = script.Parent
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)
Any help would be appreciated. I have played around with Player Lookup with Datastore but obviously am missing something.
Thanks!

3 comments
when you reset does it teleport you to the stage 9 spawn?
playerFromCharacter is deprecated, use GetPlayerFromCharacter.
Yes, When I reset the teleportation works fine. When I quit the game and rejoin I am placed back at the beginning spawn but my level still says I am on Stage 9