OrderedDataStore/Leaderboard intlimit

Hello! Currently I’m trying to make a leaderboard system for my game. This would be a list of the top 100 players with the most cash. (This game uses the Steal a Thing kit by aGoldenMilk)

The current issue I’m facing is that the OrderedDataStore feature is capped by the integer limit, and I’m using numbervalues. The game is meant to have big numbers so I can’t use integer values.

I’ve tried searching on the devforum but I haven’t seen any topics about this. I also even tried asking ChatGPT (:sob:).

If anyone needs any of the modules I’d be happy to give them.

local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserService = game:GetService("UserService")

local Numbers = require(ReplicatedStorage.Modules:WaitForChild("Numbers"))

local MoneyOrderedDataStore = DataStoreService:GetOrderedDataStore("Money")

local MoneyLeaderboard = script.Parent
local MoneyLeaderboardGui = MoneyLeaderboard:WaitForChild("MoneyLeaderboardGui")
local MoneyLeaderboardFrame = MoneyLeaderboardGui:WaitForChild("MoneyLeaderboardFrame")
local ItemsContainer = MoneyLeaderboardFrame:WaitForChild("Items")
local ItemTemplate = script:WaitForChild("Item")

local Updating = false

local function UpdateMoneyLeaderboard()
	if Updating then return end
	Updating = true

	for _, Item in ipairs(ItemsContainer:GetChildren()) do
		if Item:IsA("Frame") then
			Item:Destroy()
		end
	end

	local Success, Page = pcall(function()
		return MoneyOrderedDataStore:GetSortedAsync(false, 100, 1)
	end)

	if not Success or not Page then
		Updating = false
		return
	end

	local Data = Page:GetCurrentPage()
	for Index, Entry in ipairs(Data) do
		local UserId = tonumber(Entry.key)
		if UserId and UserId > 0 then
			task.spawn(function()
				local Item = ItemTemplate:Clone()
				Item.LayoutOrder = Index
				Item.Parent = ItemsContainer

				Item.Index.Text = "#" .. tostring(Index)
				Item.Money.Text = string.format("$%s", Numbers.Format(Entry.value or 0))

				local Thumbnail = Item:FindFirstChild("Thumbnail")
				if Thumbnail then
					Thumbnail.Image = string.format("https://www.roblox.com/headshot-thumbnail/image?userId=%d&width=420&height=420&format=png", UserId)
				end
				
				local UserSuccess, Info = pcall(function()
					return UserService:GetUserInfosByUserIdsAsync({UserId})
				end)
				
				if UserSuccess and Info and #Info > 0 then
					local User = Info[1]

					Item.Name = User.Username
					Item.Player.Text = string.format("%s (@%s)", User.DisplayName, User.Username)
				end
				
				Item.Visible = true
			end)

			task.wait(0.1)
		end
	end

	Updating = false
end

while true do
	pcall(UpdateMoneyLeaderboard)
	task.wait(60)
end

Integers and Numbers are almost the exact same thing, the difference between the two is that Integers are actually better to use (memory-wise for large numbers) as they can only represent WHOLE numbers.

Integers have 2 modes: Signed and Unsigned.
Signed Integers can represent both positive and negative numbers
Unsigned Integers can only represent positive numbers.

OrderedDataStores require integers, and the limit is 2^63. That’s 9,223,372,036,854,775,808 to be exact.

I found this response on a similar post that seems to solve the problem:
https://devforum.roblox.com/t/ordered-data-store-is-not-saving-large-numbers/3272576/3

1 Like