Problem with global leaderboard

I am trying to make global leaderboard, but its not working

local DataStoreService = game:GetService("DataStoreService")
local Store = DataStoreService:GetOrderedDataStore("Money")

local T = {"K","M","B","T","q","Q","s","S","O","N","d","U","D"}

local function roundNumber(n)
	if not tonumber(n) then return n end
	if n < 10000 then return math.floor(n) end
	local d = math.floor(math.log10(n)/3)*3
	local s = tostring(n/(10^d)):sub(1,5)
	return s.." "..tostring(T[math.floor(d/3)])
end

local function updateLeaderboard()
	local succses, err = pcall(function()
		warn("1")
		local Data = Store:GetSortedAsync(false,10)
		local StorePage = Data:GetCurrentPage()
		
		for Rank,data in ipairs(StorePage) do -- loop is not starthing
			warn("2")
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local neederData = data.Value
			local isOnLeaderboard = false
			
			for i,v in pairs(script.Parent.Main.SurfaceGui.ScrollingFrame:GetChildren()) do
				if v.name == userName then
					isOnLeaderboard = true
					warn("Already on leaderboard")
					break
				end
			end
			
			if neederData and isOnLeaderboard == false then
				local newFrame = script.Template:Clone()
				newFrame.Name = userName
				newFrame.PlayerName.Text = userName
				newFrame.ValueOfValue.Text = roundNumber(neederData)"$"
				warn("4")
			end
		end
	end)
	
	if not succses then
		warn(err)
	end
end

game.Players.PlayerRemoving:Connect(function(player)
	if script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name) then
		script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name):Destroy()
	end
end)

while wait(5) do -- i  put 5 sec for a test
	warn("Starting")
	updateLeaderboard()
end

My problem is for loop on line 20 is not starting.

I will appreciate any help :hugs:

You forgot to concatenate the “$” and also to set the parent at the end:

local DataStoreService = game:GetService("DataStoreService")
local Store = DataStoreService:GetOrderedDataStore("Money")

local T = {"K","M","B","T","q","Q","s","S","O","N","d","U","D"}

local function roundNumber(n)
	if not tonumber(n) then return n end
	if n < 10000 then return math.floor(n) end
	local d = math.floor(math.log10(n)/3)*3
	local s = tostring(n/(10^d)):sub(1,5)
	return s.." "..tostring(T[math.floor(d/3)])
end

local function updateLeaderboard()
	local succses, err = pcall(function()
		warn("1")
		local Data = Store:GetSortedAsync(false,10)
		local StorePage = Data:GetCurrentPage()

		for Rank,data in ipairs(StorePage) do -- loop is not starthing
			warn("2")
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local neederData = data.Value
			local isOnLeaderboard = false

			for i,v in pairs(script.Parent.Main.SurfaceGui.ScrollingFrame:GetChildren()) do
				if v.name == userName then
					isOnLeaderboard = true
					warn("Already on leaderboard")
					break
				end
			end

			if neederData and isOnLeaderboard == false then
				local newFrame = script.Template:Clone()
				newFrame.Name = userName
				newFrame.PlayerName.Text = userName
				newFrame.ValueOfValue.Text = roundNumber(neederData) .."$"
				newFrame.Parent = script.Parent.Main.SurfaceGui.ScrollingFrame
			end
		end
	end)

	if not succses then
		warn(err)
	end
end

game.Players.PlayerRemoving:Connect(function(player)
	if script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name) then
		script.Parent.Main.SurfaceGui.ScrollingFrame:FindFirstChild(player.Name):Destroy()
	end
end)

while wait(5) do -- i  put 5 sec for a test
	warn("Starting")
	updateLeaderboard()
end

Thats right, i forgot, but loop is still not working.
You see this

warn("2")

right after the loop? it is not printing

It shouldn’t be printing because you put it in a pcall.
Pcalls only return the result, nothing inside is printed.

Example:

pcall(function()
	error("E")
end)

This won’t print anything.

for strange reason warn("1") is printing :thinking:

That’s weird, is it the first warn(“1”) or is it the warn(err) that’s producing the warning?

its warn("1") on line 16

you can see this here:

image
image

Usually for loops don’t start because the table is empty can you print the table and send the output

You are correct, table is empty, but why?

I don’t know seems that you even followed Roblox’s guide on DataStorePages but you are not advancing to the next page and are you sure that the data store is not empty?