Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My frame won't appear on my Leaderboard?

Asked by 4 years ago

When i test out my game, everything works except that the frame won't appear, is there something wrong?

local DataStoreService = game:GetService("DataStoreService")
local ExpLeaderboard = DataStoreService:GetOrderedDataStore("ExpLeaderboard")

local function updateLeaderboard()
    local success, errorMessage = pcall(function()
        local Data = ExpLeaderboard:GetSortedAsync(false, 5)
        local ExpPage = Data:GetCurrentPage()
        for Rank, data in ipairs(ExpPage) do
            local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
            local Name = userName
            local Exp = data.Value
            local isOnLeaderboard = false
            for i, v in pairs(game.Workspace.Maps.HillsMap.Leaderboard.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
                if v.Player.Text == Name then
                    isOnLeaderboard = true
                    break
                end
            end

            if Exp and isOnLeaderboard == false then
                local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
                newLbFrame.Player.Text = Name
                newLbFrame.Exp.Text = Exp
                newLbFrame.Rank.Text = "#"..Rank
                newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.Maps.HillsMap.Leaderboard.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
                newLbFrame.Parent = game.Workspace.Maps.HillsMap.Leaderboard.GlobalLeaderboard.LeaderboardGUI.Holder
            end
        end
    end)

    if not success then
        print(errorMessage)
    end
end

while true do

    for _, player in pairs(game.Players:GetPlayers()) do
        ExpLeaderboard:SetAsync(player.UserId, player.leaderstats.Exp.Value)
    end

    for _, frame in pairs(game.Workspace.Maps.HillsMap.Leaderboard.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
        frame:Destroy()
    end

    updateLeaderboard()
    print("Updated")

    wait(10)
end

Answer this question