Global leaderboard with abbreviations

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I have a global leaderboards script and i tried adding formating so that i can save space on the boards(150000 to 150k example).
  2. What is the issue? Include screenshots / videos if possible!
    im getting an error that idk how to fix
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve searched everywhere for an example of these but couldn’t find any.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- [ SETTINGS ] --

local StatsName = "Gold" -- Your stats name
local MaxItems = 100 -- Max number of items to be displayed on the leaderboard
local MinValueDisplay = 1 -- Any numbers lower than this will be excluded
local MaxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local UpdateEvery = 5 -- (in seconds) How often the leaderboard has to update

-- [ END SETTINGS ] --

-- Don't edit if you don't know what you're doing --

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = script.Parent
local Sample = script.Sample
local List = SurfaceGui.Frame.List
local ItemsFrame = List.ListContent.Items

local function GetItems()
	local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
	local TopPage = Data:GetCurrentPage()
	ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false
	for i, v in ipairs(TopPage) do
		local UserId = v.key
		local Value = v.value
		local Username = "[Not Available]"
		local Color = Color3.fromRGB(38, 50, 56)
		local Success, Error = pcall(function()
		 	Username = game.Players:GetNameFromUserIdAsync(UserId)
		if i == 1 then
			Color = Color3.fromRGB(255, 215, 0)
		elseif i == 2 then
			Color = Color3.fromRGB(192, 192, 192)
		elseif i == 3 then
			Color = Color3.fromRGB(205, 127, 50)
		local Item = Sample:Clone()
		Item.Name = Username
		Item.LayoutOrder = i
		Item.Values.Number.TextColor3 = Color
		Item.Values.Number.Text = i
		Item.Values.Username.Text = Username
		Item.Values.Value.Text = Value
		Item.Parent = ItemsFrame

local SuffixList = {"", "K", "M", "B", "T", "Qa", "Qi"}

local function Format(value, idp)
	local exp = math.floor(math.log(math.max(1, math.abs(value)),1000))
	local suffix = SuffixList[1 + exp] or ("e+" .. exp)
	local norm = math.floor(value * ((10 ^ idp) / (1000 ^ exp))) / (10 ^ idp)

	return("%.".. idp .. "f%s"):format(norm, suffix)

while true do
	for i, v in pairs(game.Players:GetPlayers()) do
		local Stats = v.leaderstats:WaitForChild(StatsName).Value 
		Stats.Value = Format(StatsName.Value)
		if Stats then
				DataStore:UpdateAsync(v.UserId, function(Value)
					return tonumber(Stats)
	for i, v in pairs(ItemsFrame:GetChildren()) do
		if v:IsA("ImageLabel") then
	SurfaceGui.Heading.Heading.Text = StatsName .. " Leaderboard"
	List.ListContent.GuideTopBar.Value.Text = StatsName
	List.CanvasSize =, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

For the abbreviations part.


Most efficient way of converting a number in scientific notation into a Suffix and back?

Shortening A Number

Number Shortener Not Working

What would be the better way to shorten number? (Locale aware)

How do I shorten this numbers?


CLDRTools, a tool for formatting/shortening numbers, getting plurals etc. (Undocumented!)

[2.3.0] FormatNumber - Format numbers easily

I also don’t want to count to line 61 to know what part induces the error, but on line 61 try ensuring the argument you pass is not nil.

Edit: please bother to at the very least, read this part again:

on line 61 try ensuring the argument you pass is not nil.

I don’t know what you’re doing but you can rectify your algorithm to ensure nil isn’t encountered and passed as an argument.

Line 61’s code is: local exp = math.floor(math.log(math.max(1, math.abs(value)),1000))
Ill take a look at those links