#global leaderboard

24 messages · Page 1 of 1 (latest)

royal fiber
#

local statsName = "Cash"
local maxItems = 100
local minValueDisplay = 1
local maxValueDisplay = 1e300
local abbreviateValue = true
local updateEvery = 10

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("Cash")
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 = require(game.ReplicatedStorage.SNotation)

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 ABBREVIATIONS.short(value) or value
    item.Parent = Contents.Items
end

end

#

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

    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(player.Stats.Cash.Value)
        end)
    end)
end
for i, item in pairs(Contents.Items:GetChildren()) do
    if item:IsA("Frame") then
        item:Destroy()
    end
end

getItems()

wait()
Contents.GuideTopBar.Value.Text = statsName
wait(updateEvery)

end

royal fiber
#

nvm i did it

cerulean mason
cerulean mason
#

so are u using a IntValue

cerulean mason
#

na he should

#

because

#

they are the same

#

ipairs just prints out

1. 0
2. 1k
3. 1m
4. 1b
5. 1t``` and so on if he did a print
#

then pairs

0 1k
1m 1b
1t 1qd```
#

they are still

#

nope

misty iron
#

pairs isnt needed in Luau

#

isnt ipairs analogous to a for x = 1 #t do loop?

#

or does it work with mixed tables or something

#

either way, ive never ran into a situation ive needed them

cerulean mason
misty iron
#

they are more efficient iirc from my last benchmark to iterate thru arrays

#

ipairs() function will print the order of the key in numeric order,

#

is what some website says

cerulean mason
#

ye thats what i just read also

misty iron
#

so i assume they are functionally identical, just its be less efficient

misty iron
royal fiber
#

Thanks but i figured it out