#Obby checkpoint bug

1 messages · Page 1 of 1 (latest)

dense robin
#

I have a bug when the player leaves midgame, their stage score is either not correct OR doesn't update in the leaderstats when they continue playing. Their stages are registered however, it just doesn't update on the leaderstats

#

Here's my script: ```local function save(player)
local userIdStr = tostring(player.UserId)
local pFolder = PlayerDataFolder:FindFirstChild(userIdStr)
if not pFolder then return end
local stageObj = pFolder:FindFirstChild("Stage")
local stats = player:FindFirstChild("leaderstats")
if not stageObj or not stats then return end

local data = {
    Stage = stageObj.Value,
    Rebirths = stats.Rebirths.Value;
}


local success, errorMessage = pcall(function()
    StageDataStore:SetAsync(userIdStr, data)
end)
if not success then
    warn("Save failed for " .. player.Name .. ": " .. tostring(errorMessage))
end

return success

end```

#
    local userIdStr = tostring(player.UserId)
    local PlayerFolder = Instance.new("Folder")
    PlayerFolder.Name = userIdStr
    PlayerFolder.Parent = PlayerDataFolder

    local currentStage = Instance.new("IntValue")
    currentStage.Name = "Stage"
    currentStage.Value = 0
    currentStage.Parent = PlayerFolder

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local stagedisplay = Instance.new("IntValue")
    stagedisplay.Name = "Stage"
    stagedisplay.Value = currentStage.Value
    stagedisplay.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Value = 0
    rebirths.Parent = leaderstats

    local time = Instance.new("IntValue")
    time.Name = "TotalTime"
    time.Value = 0


    local st, dt = pcall(function()
        return total_time_played_datastore:GetAsync(userIdStr)
    end)

    if st and dt then time.Value = dt end

    currentStage.Changed:Connect(function()
        stagedisplay.Value = currentStage.Value
    end)

    local success, data = pcall(function()
        return StageDataStore:GetAsync(userIdStr)
    end)

    if success and type(data) == "table" then
        currentStage.Value = data.Stage or 0
        rebirths.Value = data.Rebirths or 0
    else
        currentStage.Value = 0
        rebirths.Value = 0
    end```
#
        local spawnPart = spawns:FindFirstChild(tostring(currentStage.Value))
        if spawnPart then
            player.RespawnLocation = spawnPart
            local char = player.Character or player.CharacterAdded:Wait()
            if char:FindFirstChild("HumanoidRootPart") then
                char.HumanoidRootPart.CFrame = spawnPart.CFrame + Vector3.new(0,3,0)
            end
        end
    end

    local timeTracking = Instance.new("NumberValue")
    timeTracking.Name = "TimeTracking"
    timeTracking.Value = 0
    timeTracking.Parent = player
    trackingValues[player.UserId] = timeTracking
end```
barren ore
#

well it seems that the position they were last at saves so you can add a part somewhere on the checkpoint that sets the players stage

#

ill look at ur code if u do want to do it that way tho

#

ill get back to this later

dense robin
#

if that’s what you mean

upbeat helm
red jettyBOT
#

studio** You are now Level 2! **studio

upbeat helm
#

zip it mee6 bro

upbeat helm
#

I actually made a class specifically for handling a player's leaderstats, if you like I can send it to you

upbeat helm
#

cuz you said it was just like

#

the leaderstats wouldnt update but it worked fine in the code right