#Saving checkpoint system

1 messages · Page 1 of 1 (latest)

boreal moon
#

No errors, only allows me to get up to stage 11 then quits working.

cobalt igloo
#

@boreal moon

#

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ObbyDataStore = DataStoreService:GetDataStore("ObbyDataStore")

local Checkpoints = workspace:WaitForChild("Checkpoints")

local function onTouched(hit, checkpoint)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)

if player then
    local leaderstats = player:FindFirstChild("leaderstats")
    local stage = leaderstats and leaderstats:FindFirstChild("Stage")
    
    if stage then
        local checkpointNumber = tonumber(checkpoint.Name)
        -- Only update if the player is actually moving forward
        if checkpointNumber == stage.Value + 1 then
            stage.Value = checkpointNumber
        end
    end
end

end

-- Hook up all checkpoints in the folder
for _, checkpoint in pairs(Checkpoints:GetChildren()) do
checkpoint.Touched:Connect(function(hit)
onTouched(hit, checkpoint)
end)
end

#

see if this works