#help with leaderboard

1 messages · Page 1 of 1 (latest)

simple plinth
#

my global leaderboard is seeing that the rocks stat exists but it wont update on my leaderboard. when i edit the value of the stat with the console (Game.Players.x.leaderstats.rocks.Value = x) it works but gaining the leaderstat from gameplay doesnt work.

#

for example when you click with the rock it adds +1

#

but it doesnt work on the leaderboard

spare latch
#

where code

simple plinth
#

what code do you need

#

the leaderboard?

simple plinth
# spare latch

local statsName = "rocks"
local maxItems = 50
local minValueDisplay = -1
local maxValueDisplay = 10e15
local abbreviateValue = true
local updateEvery = 5
local headingColor = Color3.fromRGB(106, 57, 9)

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
Default = Color3.fromRGB(38, 50, 56),
Gold = Color3.fromRGB(255, 215, 0),
Silver = Color3.fromRGB(192, 192, 192),
Bronze = Color3.fromRGB(205, 127, 50)
}
local ABBREVIATIONS = { "K", "M", "B", "T" }

local function toHumanReadableNumber(num)
if num < 1000 then
return tostring(num)
end

local digits = math.floor(math.log10(num)) + 1
local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
local front = num / math.pow(10, index * 3)

return string.format("%.2f%s+", front, ABBREVIATIONS[index])

end

local function getItems()
local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
local topPage = data:GetCurrentPage()

Contents.Items.Nothing.Visible = #topPage == 0 and true or false

for position, v in ipairs(topPage) do
    local userId = v.key
    local value = v.value
    local username = "[Not Available]"
    local color = COLORS.Default

    local success, err = pcall(function()
        username = Players:GetNameFromUserIdAsync(userId)
    end)

    if position == 1 then
        color = COLORS.Gold
    elseif position == 2 then
        color = COLORS.Silver
    elseif position == 3 then
        color = COLORS.Bronze
    end
#

local item = Template:Clone()
item.Name = username
item.LayoutOrder = position
item.Values.Number.TextColor3 = color
item.Values.Number.Text = position
item.Values.Username.Text = username
item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
item.Parent = Contents.Items
end
end

script.Parent.Parent.Color = headingColor
Frame.Heading.ImageColor3 = headingColor
Frame.Heading.Bar.BackgroundColor3 = headingColor

while true do
for _, player in pairs(Players:GetPlayers()) do
local leaderstats = player:FindFirstChild("leaderstats")

    if not leaderstats then
        warn("Couldn't find leaderstats!")
        break
    end

    local statsValue = leaderstats:FindFirstChild(statsName)

    if not statsValue then
        warn("Couldn't find " .. statsName .. " in leaderstats!")
        break
    end

    pcall(function()
        DataStore:UpdateAsync(player.UserId, function()
            return tonumber(statsValue.Value)
        end)
    end)
end

for _, item in pairs(Contents.Items:GetChildren()) do
    if item:IsA("Frame") then
        item:Destroy()
    end
end

getItems()

wait()
Frame.Heading.Heading.Text =  "top rock eaters"
Contents.GuideTopBar.Value.Text = statsName
wait(updateEvery)

end

#

you're a godsend btw

#

wait

#

how do i send it in lua

tacit comet
simple plinth
#
local statsName = "rocks" 
local maxItems = 50 
local minValueDisplay = -1 
local maxValueDisplay = 10e15 
local abbreviateValue = true 
local updateEvery = 5 
local headingColor = Color3.fromRGB(106, 57, 9) 








local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
    Default = Color3.fromRGB(38, 50, 56),
    Gold = Color3.fromRGB(255, 215, 0),
    Silver = Color3.fromRGB(192, 192, 192),
    Bronze = Color3.fromRGB(205, 127, 50)
}
local ABBREVIATIONS = { "K", "M", "B", "T" }


local function toHumanReadableNumber(num)
    if num < 1000 then
        return tostring(num)
    end
    
    local digits = math.floor(math.log10(num)) + 1
    local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
    local front = num / math.pow(10, index * 3)
    
    return string.format("%.2f%s+", front, ABBREVIATIONS[index])
end

local function getItems()
    local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
    local topPage = data:GetCurrentPage()

    Contents.Items.Nothing.Visible = #topPage == 0 and true or false

    for position, v in ipairs(topPage) do
        local userId = v.key
        local value = v.value
        local username = "[Not Available]"
        local color = COLORS.Default

        local success, err = pcall(function()
            username = Players:GetNameFromUserIdAsync(userId)
        end)

        if position == 1 then
            color = COLORS.Gold
        elseif position == 2 then
            color = 
#
COLORS.Silver
        elseif position == 3 then
            color = COLORS.Bronze
        end

        local item = Template:Clone()
        item.Name = username
        item.LayoutOrder = position
        item.Values.Number.TextColor3 = color
        item.Values.Number.Text = position
        item.Values.Username.Text = username
        item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
        item.Parent = Contents.Items
    end
end


script.Parent.Parent.Color = headingColor
Frame.Heading.ImageColor3 = headingColor
Frame.Heading.Bar.BackgroundColor3 = headingColor

while true do
    for _, player in pairs(Players:GetPlayers()) do
        local leaderstats = player:FindFirstChild("leaderstats")

        if not leaderstats then
            warn("Couldn't find leaderstats!")
            break
        end

        local statsValue = leaderstats:FindFirstChild(statsName)

        if not statsValue then
            warn("Couldn't find " .. statsName .. " in leaderstats!")
            break
        end

        pcall(function()
            DataStore:UpdateAsync(player.UserId, function()
                return tonumber(statsValue.Value)
            end)
        end)
    end

    for _, item in pairs(Contents.Items:GetChildren()) do
        if item:IsA("Frame") then
            item:Destroy()
        end
    end

    getItems()

    wait()
    Frame.Heading.Heading.Text =  "top rock eaters"
    Contents.GuideTopBar.Value.Text = statsName
    wait(updateEvery)
end
#

@spare latch can you pretty please with a cherry on top help

shrewd scarabBOT
#

studio** You are now Level 5! **studio

simple plinth
#

figured it out we're god