How to update global leaderboard

so i followed a tutorial from BrawlDev which is good, a learn thing or two but the problem is that he ended the tutorial without finishing it and i have no idea how to update the leaderboard

here`s the code:

local DataStoreService = game:GetService('DataStoreService')

local myData = DataStoreService:GetOrderedDataStore('MyDataRebirths')

local item = script:WaitForChild("Item")
local playerContainer = script.Parent.screen.SurfaceGui.Container.PlayerContainer

game.Players.PlayerAdded:Connect(function(plr)
	task.wait()
	local rebirths = plr.leaderstats.Rebirths
	
	while true do
		task.wait(10)
		
		local success, errorMsg = pcall(function()
			myData:SetAsync(plr.UserId, rebirths.Value)
		end)
		if not success then
			print(errorMsg)
		end
	end
end)

while true do
	task.wait(10)
	
	local success, pages = pcall(function()
		return myData:GetSortedAsync(false, 10)
	end)
	
	if success then
		local entries = pages:GetCurrentPage()
		
		for rank, entry in pairs(entries) do
			local clonedItem = item:Clone()
			
			local username = game.Players:GetNameFromUserIdAsync(entry.key)
			
			if username then
				clonedItem.Name = username
				clonedItem.NameText.Text = username
			end
			
			clonedItem.CashText.Text = entry.value
			clonedItem.RankText.Text = rank
			
			clonedItem.Parent = playerContainer
		end
	end
end

and it looks like that
image

it just repeats and i dont know how to make it refresh please help

This code should be updating the leaderboard every 10 seconds but it’s really bad and inefficient. I suggest you watch a better tutorial by someone else.

1 Like