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

OrderedDataStore putting those with 0 cash first instead the ones with cash why?

Asked by
DevingDev 346 Moderation Voter
5 years ago
Edited 5 years ago

I have this OrderedDataStore script which is pretty stupidly made and hella messy.

The script updates two boards but only one of the board seems to be working fine, putting the one with the most amount at the top but the other board puts the people with 0 as their amount on the top and not the actual one with the most amount.

Modulescript on the server side:

local Top100Richest = workspace:FindFirstChild("Top100Richest")
local RichestBackground = Top100Richest:FindFirstChild("Background")
local RichestSurfaceGui = RichestBackground:FindFirstChild("SurfaceGui")
local RichestContainer = RichestSurfaceGui:FindFirstChild("Container")

local module = {}

local CashDataKey = game:GetService("DataStoreService"):GetOrderedDataStore("TestDatastoreCash1")

local function updateCashBoard(data)
    for k,v in pairs(data) do
        local pos = k
        local name = v.key
        local score = v.value

        local Sample = RichestContainer:FindFirstChild(pos)
        Sample.PlayerName.Text = name
        Sample.Cash.Text = score
    end 
end

local function HandleCashBoardSaving()
    while true do
        local success, message = pcall(function()
            local pages = CashDataKey:GetSortedAsync(false, 100)

            local data = pages:GetCurrentPage() 

            updateCashBoard(data)

            if not pages.IsFinished then            

                pages:AdvanceToNextPageAsync()          
                data = pages:GetCurrentPage()

                updateCashBoard(data)
            end
        end)

        if not success then
            print(message)
        end

        wait(60) -- Update time.
    end
end

function module:SetupBoard()    
    HandleCashBoardSaving()
end


return module


0
Know any part you think is the issue? 158 lines ain't fun to skim through. Try including it when you post large pieces of code. xPolarium 1388 — 5y
0
imma make it shorter DevingDev 346 — 5y

Answer this question