Не работает изменение числа

Столкнулся с проблемой, когда делал скрипт на Lua для Roblox Studio. Хочу сделать так, чтобы в зависимости от значения чекпоинта в LeaderBoard (там всё работает) менялось значение TextLabel "Level". Если знаете как это сделать, помогите пожалуйста! Код снизу:

local player = game.Players.LocalPlayer
local checkpointFolder = workspace:WaitForChild("Checkpoints")
local teleportOffset = Vector3.new(0, 5, 0) 
local textLevel = script.Parent:WaitForChild("Level")
local currentCheckpoint = player:WaitForChild("leaderstats"):WaitForChild("Checkpoint")


local function teleportToCheckpoint(checkpointNumber)
    if checkpointNumber <= #checkpointFolder:GetChildren() and checkpointNumber > 0 then
        local checkpoint = checkpointFolder:FindFirstChild("Checkpoint" .. checkpointNumber)
        if checkpoint then
            local activated = checkpoint:GetAttribute("Activated") or false
            if activated then
                local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
                if humanoidRootPart then
                    local checkpointPosition = checkpoint.Position + teleportOffset
                    humanoidRootPart.CFrame = CFrame.new(checkpointPosition)
                    currentCheckpoint.Value = checkpointNumber
                end
            else
                warn("Player attempted to teleport to inactive checkpoint:", checkpointNumber)
            end
        else
            warn("Player attempted to teleport to non-existent checkpoint:", checkpointNumber)
        end
    end
end


local function updateLevel()
    textLevel.Text = tostring(currentCheckpoint.Value)
    print("Current Checkpoint:", currentCheckpoint.Value)
end

updateLevel()


script.Parent.Right.MouseButton1Click:Connect(function()
    local newCheckpoint = currentCheckpoint.Value + 1
    if newCheckpoint <= #checkpointFolder:GetChildren() then
        local nextCheckpoint = checkpointFolder:FindFirstChild("Checkpoint" .. newCheckpoint)
        local activated = nextCheckpoint and nextCheckpoint:GetAttribute("Activated") or false
        if activated then
            teleportToCheckpoint(newCheckpoint)
            updateLevel()
        else
            warn("Invalid checkpoint number:", newCheckpoint)
        end
    else
        warn("Invalid checkpoint number:", newCheckpoint)
    end
end)

script.Parent.Left.MouseButton1Click:Connect(function()
    local newCheckpoint = currentCheckpoint.Value - 1
    if newCheckpoint >= 0 then
        local prevCheckpoint = checkpointFolder:FindFirstChild("Checkpoint" .. newCheckpoint)
        local activated = prevCheckpoint and prevCheckpoint:GetAttribute("Activated") or false
        if activated then
            teleportToCheckpoint(newCheckpoint)
            updateLevel()
        else
            warn("Invalid checkpoint number:", newCheckpoint)
        end
    else
        warn("Invalid checkpoint number:", newCheckpoint)
    end
end)

print("Current Checkpoint:", currentCheckpoint.Value)

Ответы (0 шт):