#leaderboard script help

1 messages · Page 1 of 1 (latest)

gilded locust
#

local players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Orderedstores = {}

local MAX_ROWS = 100
local UPDATE_INTERVAL = 15 -- seconds
local ROW_TEMPLATE = ReplicatedStorage:WaitForChild("LeaderboardRow")

function getOrderedStore(CurrencyName)
if not Orderedstores[CurrencyName] then
Orderedstores[CurrencyName] = DataStoreService:GetOrderedDataStore(CurrencyName)
end
return Orderedstores[CurrencyName]
end

function ClearLeaderboard(surfaceGui)
for _, child in ipairs(gui.DataContent:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
end

function updateLeaderboard(leaderboardModel)

local background = leaderboardModel:WaitForChild("Background")
local surfaceGui = background:WaitForChild("SurfaceGui")
local currencyName = leaderboardModel:WaitForChild(Currency).Value
local folderName = leaderboardModel:WaitForChild("FolderName").Value

local store = getOrderedStore(currencyName)

local success, pages = pcall(function()
    return store:getSortedAsync(false, MAX_ROWS)
end)

if not success then
    warn("Failed to get leaderboard data for " .. currencyName)
    return
end
#

heres the rest

#

ClearLeaderboard(surfaceGui)

local CurrentPage = pages:GetCurrentPage()

for rank, entry in ipairs(CurrentPage) do
    local userId =(entry.key)
    local value = entry.value

    local Username = "loading"
    pcall(function() 
        Username = players:GetNameFromUserIdAsync(userId)
    end)

    local row = ROWTEMPLATE:Clone()
    row.PlayerLabel.Text = Username
    row.CurrencyLabel.Text = value
    row.RankLabel.Text = "#" .. rank

        row.LayoutOrder = rank
        row.Parent = surfaceGui.DataContent
    end
end

end

function SaveAllPlayers()
for , player in pairs(game.Players:GetPlayers()) do
for , leaderboardModel in pairs(workspace.Leaderboards:GetChildren()) do
If string.match(leaderboardModel.Name, "Leaderboard")
and leaderboardModel:FindFirstChild("Currency")
and leaderboardModel;:FindFirstChild("FolderName") then

#

local Currency = leaderboardModel.Currency.Value
local FolderName = leaderboardModel.FolderName.Value

            local stats.folder = player:FindFirstChild(FolderName)
            if not statsFolder then continue end

            local stat = player:FindFirstChild("Currency")
            if not stat then continue end

            local OrderedStore = getOrderedStore(Currency)
            local store = getOrderedStore(Currency)

            pcall(function()
                store:SetAsync(player.UserId, stat.Value)
            end)
        end

    end
end

end

While true do
SaveAllPlayers()
for , leaderboardModel in pairs(workspace.Leaderboards:GetChildren()) do
If string.match(leaderboardModel.Name, "Leaderboard")
and leaderboardModel:FindFirstChild("Currency")
and leaderboardModel;:FindFirstChild("FolderName")
and LeaderboardModel: FindFirstChild("background")
and leaderboardModel.background:FindFirstChild("SurfaceGui") then

        updateLeaderboard(leaderboardModel)

    end
end

print("All LeaderBoards Updated.")
task.wait(UPDATE_INTERVAL)

end

pallid oak
#

That will let you format your code so it's easier to look at

#

And I need details on what the issue is

ocean fern
#

looks fine to me

#

whats wrong with it

gilded locust
gilded locust
runic novaBOT
#

studio** You are now Level 1! **studio

blissful heart
next seal
#
local players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Orderedstores = {}

local MAX_ROWS = 100
local UPDATE_INTERVAL = 15 -- seconds 
local ROW_TEMPLATE = ReplicatedStorage:WaitForChild("LeaderboardRow")

function getOrderedStore(CurrencyName)
    if not Orderedstores[CurrencyName] then 
        Orderedstores[CurrencyName] = DataStoreService:GetOrderedDataStore(CurrencyName)
    end
    return Orderedstores[CurrencyName]
end

function ClearLeaderboard(surfaceGui) 
    for _, child in ipairs(gui.DataContent:GetChildren()) do
        if child:IsA("Frame") then
            child:Destroy()
        end
    end
end


function updateLeaderboard(leaderboardModel)
    
    local background = leaderboardModel:WaitForChild("Background")
    local surfaceGui = background:WaitForChild("SurfaceGui")
    local currencyName = leaderboardModel:WaitForChild(Currency).Value
    local folderName = leaderboardModel:WaitForChild("FolderName").Value
    
    local store = getOrderedStore(currencyName)
    
    local success, pages = pcall(function()
        return store:getSortedAsync(false, MAX_ROWS)
    end)
    
    if not success then
        warn("Failed to get leaderboard data for " .. currencyName)
        return
    end
#
local Currency = leaderboardModel.Currency.Value
                local FolderName = leaderboardModel.FolderName.Value

                local stats.folder = player:FindFirstChild(FolderName)
                if not statsFolder then continue end

                local stat = player:FindFirstChild("Currency")
                if not stat then continue end

                local OrderedStore = getOrderedStore(Currency)
                local store = getOrderedStore(Currency)

                pcall(function()
                    store:SetAsync(player.UserId, stat.Value)
                end)
            end

        end
    end

end

While true do
    SaveAllPlayers()
    for , leaderboardModel in pairs(workspace.Leaderboards:GetChildren()) do
        If string.match(leaderboardModel.Name, "Leaderboard") 
            and leaderboardModel:FindFirstChild("Currency")
            and leaderboardModel;:FindFirstChild("FolderName") 
            and LeaderboardModel: FindFirstChild("background") 
            and leaderboardModel.background:FindFirstChild("SurfaceGui") then

            updateLeaderboard(leaderboardModel)

        end
    end

    print("All LeaderBoards Updated.")
    task.wait(UPDATE_INTERVAL)
end
#

idk if it works im on mobilei was talking about the text format lol i didnt change anything

gilded locust
#

this is the error code im gettig. 13:20:37.235 ServerScriptService.GlobalBoardHandler:69: Expected <eof>, got 'end' - Studio - GlobalBoardHandler:69

ocean fern
#

lowercase

#

same with If

#

local stats.folder??

#

you have way more errors than you think

#

did you try copying a tutorial line for line?