As you read in the title, I'm trying to make a global leaderboard. It works, but it doesn't consistently work. What I mean is, if I have 0 credits, then it'll show 0 credits. After 30 seconds, if I have a different value than 0, then it should update on the leaderboard. However, it doesn't seem to update the leaderboard. Also, there's no errors in the output occurring. Help?

--SCRIPT--

local lb = game:GetService("DataStoreService"):GetOrderedDataStore("candyjumperstats")

function addcommas(num)
	return tostring(math.floor(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-7)$","%1"):reverse()
end

function update()
	for _,plr in next, game:GetService("Players"):GetPlayers() do
		pcall(function()
			lb:UpdateAsync(plr.UserId, function() return plr:WaitForChild("HighScore").Value end)
		end)
	end
	
	local data = lb:GetSortedAsync(false,10)
	local page = data:GetCurrentPage()
	
	for rank,info in next, page do
		pcall(function()
		local player = game:GetService("Players"):GetNameFromUserIdAsync(info.key)
		local frame = script.Parent.Frame.ScrollingFrame:FindFirstChild(rank)
		frame.User.Text = player
		frame.Rank.Text = "#"..rank
		frame.Amount.Text = addcommas(info.value)
		frame.Visible = true
	end
end	

while wait(5) do
	update()
end

2 comments

0

It is likely that the pcall function is erroring if no errors appear. Make sure "HighScore" is correctly parented to the player? GetNameFromUserIdAsync also should be wrapped in a pcall.

0

I wrapped GetNameFromUserIdAsync in a pcall function, and yes HighScore is parented correctly in the player. However, it still doesn't work. If the pcall function is erroring, how would I fix it?