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


2 comments

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.

0

imma make it shorter