[Still need help] How do i make a TOP 1 Global leaderboard?

It uses a surface gui and clones a frame and then parents it to teh scrolling frame.

local DataStore = game:GetService("DataStoreService")
local ODS = DataStore:GetOrderedDataStore("MoneyStats")
local Players = game:GetService("Players")

local Scrolling = script.Parent.Leaders

local function cleanboard()
	print("Clearing Board | function cleanbaord()")
	local Descends = Scrolling:GetChildren()
	for i, Descend in pairs(Descends) do
		if Descend:IsA("Frame") then
			Descend:Destroy()
		end
	end
end


function updateboard()
	local pages = ODS:GetSortedAsync(false, 10)
	local CurrentPage = pages:GetCurrentPage()
	warn("Update Function Provoked | function updateboard()")
	for i, v in ipairs(CurrentPage) do
		print({v.key, v.value})
		local userId = v.key
		local score = v.value
		local frame = script.Frame:Clone()
		pcall(function()
			frame.PName.Text = Players:GetNameFromUserIdAsync(userId)
		end)
		pcall(function ()
			frame.PImage.Image = Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		end)
		frame.PAmount.Text = "$"..score
		frame.PRank.Text = "#"..i
		frame.Parent = Scrolling
		warn(userId.." is ranked #"..i.." with "..score.."Cash")
	end
end


while true do 
	local success, message = pcall(function()
		cleanboard()
		task.wait(1)
		updateboard()
	end)
	if not success then
		print(message)
	end
	
	task.wait(60)
end

it gets to “warn(“Update Function Provoked | function updateboard()”)” and stops

I think the problem is that you put in ipairs instead of in pairs, but I’m not sure. Can you try changing it?

I tried and I originally had that, but I believe ipairs is better for loops, I think that is why I originally changed it, I believe I saw that in Documentation.

I did change it just now and nothing happened.

Can you print “CurrentPage” to try to see if anything is wrong there?

I did
print({CurrentPage}) and it returned:

{[1] = {}}
Im not sure what that means.

This means that “CurrentPage” has no keys. Are you sure that the datastore is not empty?

Its not empty, it loads in to the Leaderstat just fine.
I could understand if it wont work if there’s not enough Keys in the datastore, but I set it to 1 at some point and it still hasn’t come up.

Is the leaderstat loading system connected to a normal datastore or an ordered datastore?

It is connected to a normal datastore. Is that why it isn’t working?

Yes, you need to set it to an OrderedDataStore for both scripts to work. This is why nothing was in it - you were saving it to a seprate datastore

Alright it’s working now.

THANKS YOU SOOOO MUCH FOR THE HELP!

Np! I am glad I was able to help you.

1 Like

im back as i read loading system must be connected to the ordered datastore and i wonder
is this script using normal datastore or ordered?

-- datastore name is replaced because idk why
game:GetService("DataStoreService"):GetDataStore("nil"):SetAsync(player.UserId,Stat)

Edit: yeah its using datastore but uh does this script saves in ordered?

game.DataStoreService:GetOrderedDataStore("Nil"):SetAsync()

Edit 2: i wonder if i can store more than 1

why is everyone die?
man i still need help

I think you are having the same issue as me, like @shopkinspizzas helped me do, it is supposed to be “GetOrderedDataStore” instead of “GetDataStore.”

for that message, the second box of script has no setting and that is only saving, it doesn’t load data either.