How i do to get past 9.223 quintillion limit in leaderboards?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a leaderboard that gets past the 9.223 quintillion limit since they are a lot of players that have passed it in my game
  2. What is the issue? Include screenshots / videos if possible!
    I can’t get it to work.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried a solution from dev forum but i didn’t understand it. i just want to add only to get past the number limit.

Here is THE SCRIPT:

local LeaderboardService = {}

--// Services 
local players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local ds = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Variables
local DataFolder = ServerStorage:WaitForChild("Data")
local leaderboardsFol = game.Workspace:WaitForChild("Leaderboards")
local Stands = leaderboardsFol:WaitForChild("Stands")
local InvisibleBoxes = Stands:WaitForChild("InvisibleBoxes")
local NPCS = Stands:WaitForChild("NPCS")
local RepModules = ReplicatedStorage:WaitForChild("Modules")
local proto = ServerStorage.ItemStorage.Extra.LeaderboardFrame
local overAllVersion = require(DataFolder.UserDataKey).LeaderboardKeyVersion
local waitTimePerLeaderboard = (#leaderboardsFol:GetChildren()) - 1
local UpdateGoalsCounter, UpdateServerMessage = 0, 0

--// Modules
local DataController = require(DataFolder.DataController)
local TimePlayedModule = require(script.Parent.TimePlayed)
local Abbreviate = require(RepModules.Abbreviate)
local timeString = require(RepModules.TimeString)
local notOnLeaderboards = require(script.BannedLeaderboardUsers)
local CommunityGoalsModule = require(script.Parent.CommunityGoals)
local ChestServerController = require(script.Parent.Parent.Chests.ChestServerController)
local ServerChatMessagesModule = require(script.Parent.Parent.Egg.EggServerHandler.ServerChatMessages)
local PetHandler = require(script.Parent.Parent.Pet.PetHandler)

--// Leaderboards
local leaderboards = {}
for _, v in pairs(leaderboardsFol:GetChildren()) do
	if v:IsA("Model") then
		leaderboards[v.Name] = v
	end
end

--// Update Variables
local CAN_RUN_MODULE = true
local UPDATE_TIME = 180
local divider = 10000
local rebirthDivider = 1
local minimalVal = 1

--// DataStores
local Clicks_DataStore = ds:GetOrderedDataStore("Clicks_Leaderboard_"..overAllVersion)
local Gems_DataStore = ds:GetOrderedDataStore("Gems_Leaderboard_"..overAllVersion)
local Rebirths_DataStore = ds:GetOrderedDataStore("Rebirths_Leaderboard_"..overAllVersion)
local Super_Rebirths_DataStore = ds:GetOrderedDataStore("S_Rebirths_Leaderboard_"..overAllVersion)
local TimePlayed_DataStore = ds:GetOrderedDataStore("TimePlayed_Leaderboard_"..overAllVersion)
local TopEggHatch_DataStore = ds:GetOrderedDataStore("TopEggHatch_Leaderboard_"..overAllVersion)
local TopStreaks_DataStore = ds:GetOrderedDataStore("TopStreaks_Leaderboard_"..overAllVersion)

--// Local Functions
local getDataStore = function(name)
	if name == "Clicks" then
		return Clicks_DataStore
	elseif name == "Gems" then
		return Gems_DataStore
	end
end

function LeaderboardService:GetStat(plr, statName)
	return DataController:GetStatFromPlayer(plr, tostring(statName))
end

local getValForDataSet = function(plr, name)
	if name == "Clicks" then
		local clicks = LeaderboardService:GetStat(plr, "TotalClicks")

		return tonumber(clicks), true

	elseif name == "Gems" then
		local gems = LeaderboardService:GetStat(plr, "TotalGems")

		return tonumber(gems), true	

	elseif name == "Rebirths" then
		local rebirths = LeaderboardService:GetStat(plr, "TotalRebirths")

		return tonumber(rebirths), true	

	elseif name == "TopSuperRebirths" then
		local superRebirths = LeaderboardService:GetStat(plr, "TotalSuperRebirths")
		return tonumber(superRebirths), false	
	elseif name == "TopTime" then
		local timePlayed = TimePlayedModule:UpdateTimePlayed(plr)
		return timePlayed, false
	elseif name == "TopEggHatch" then
		local eggsHatched = LeaderboardService:GetStat(plr, "TotalEggsOpened")
		return eggsHatched, false
	elseif name == "TopStreaks" then
		local currentStreak, last2DayClaim = ChestServerController:GetCurrentStreak(plr, "Daily Chest")
		if (os.time() - last2DayClaim) >= (48 * 3600) then
			return 0, false
		else
			return currentStreak, false
		end
	end
end
local Round_Function = function(n)
	return (n + 0.5) - (n + 0.5) % 1
end
local errorMsg = function(msg, name, plrName)
	warn("Error For "..tostring(plrName).."'s "..tostring(name).." Leaderboard! Error:", tostring(msg))
end
local cloneUI = function(leaderboardName, rank, name, val, parent)
	if leaderboardName and rank and name and val and parent then
		if tonumber(val) >= minimalVal then 
			local clone = proto:Clone()

			clone.PlayerName.Text = tostring(name)
			clone.Rank.Text = "#"..tostring(rank)
			clone.Name = tostring(name)
			clone.LayoutOrder = tonumber(rank)

			if leaderboardName == "TopTime" then
				clone.Amount.Text = timeString(tonumber(val))
			elseif leaderboardName == "Clicks" or leaderboardName == "Gems" then
				local newVal = tonumber(val) * divider
				clone.Amount.Text = Abbreviate:ReturnShort(tonumber(newVal))
			elseif leaderboardName == "Rebirths" then
				local newVal = tonumber(val) * rebirthDivider
				clone.Amount.Text = Abbreviate:ReturnShort(tonumber(newVal))
			else
				clone.Amount.Text = Abbreviate:ReturnShort(tonumber(val))
			end

			clone.BackgroundColor3 = Color3.fromRGB(189, 136, 0)
			clone.Visible = true
			clone.Parent = parent
		end
	end
end

function LeaderboardService:BanHacker(plrName)
	spawn(function()
		local plrID = nil
		local Success, Err = pcall(function()
			plrID = players:GetUserIdFromNameAsync(tostring(plrName))
		end)
		if plrID ~= nil then
			for _, v in pairs(leaderboardsFol:GetChildren()) do
				if v:IsA("Model") then
					local leaderboardName = v.Name
					local set, fail = pcall(function()
						local data = getDataStore(leaderboardName)
						if data ~= nil then
							data:RemoveAsync(plrID)
						else
							errorMsg("DataStore was nil or not a DataStore", leaderboardName, tostring(plrName))
						end
					end)
				end
			end
		end
	end)
end

function LeaderboardService:GiveTrophyPetToPlayer(PlayerName)
	local Player = players:FindFirstChild(tostring(PlayerName))
	if Player ~= nil then
		spawn(function()
			PetHandler:GiveTrophyPet(Player)
		end)
	end
end

function LeaderboardService:UpdateNumber1Player(leaderboardName, PlayerName, PlayerUserId)
	if leaderboardName ~= nil and PlayerName ~= nil and PlayerUserId ~= nil then
		if tostring(leaderboardName) == "TopEggHatch" then return end
		spawn(function()
			local npc = NPCS:FindFirstChild(tostring(leaderboardName))
			if npc == nil then
				warn("No NPC For "..tostring(leaderboardName).."!")
				return
			end
			local OwnerTag = npc:FindFirstChild("Owner")
			if OwnerTag == nil then
				OwnerTag = Instance.new("StringValue")
				OwnerTag.Name = "Owner"
				OwnerTag.Parent = npc
			end
			if OwnerTag.Value == tostring(PlayerName) then else
				local Description
				local good, fail = pcall(function()
					Description = players:GetHumanoidDescriptionFromUserId(PlayerUserId)
				end)
				if good and not fail then
					if Description ~= nil then
						local humanoid = npc:FindFirstChild("Humanoid")
						if humanoid ~= nil then
							humanoid:ApplyDescription(Description)
							OwnerTag.Value = tostring(PlayerName)
						end
					end
				else
					warn("Error On Gett Humanoid Description From UserId: ".. tostring(PlayerUserId))
				end
			end
		end)
	end
end

local cache = {}
local function GetNameFromUserId(userId)
	if userId == nil then
		return "[ Name Didn't Load ]"
	end
	if tonumber(userId) <= 0 then
		return "[ Name Didn't Load ]"
	end
	if cache[userId] then 
		return cache[userId] 
	end
	local player = players:GetPlayerByUserId(userId)
	if player then
		cache[userId] = player.Name
		return player.Name
	end 
	local name
	local set, err = pcall(function()
		name = players:GetNameFromUserIdAsync(userId)
	end)
	if set and not err then
		cache[userId] = name
		return name
	else
		warn("Error On Getting Player Name From UserId (".. tostring(userId)..")")
	end
	return "[ Name Didn't Load ]"
end

function LeaderboardService:UpdateLeaderboard(leaderboardName, data, parent, start)
	if leaderboardName ~= nil and data ~= nil and parent ~= nil then
		local page = nil
		local Success, Err = pcall(function()
			local Data = data:GetSortedAsync(false, 100)
			page = Data:GetCurrentPage()
		end)
		if Success and not Err and page ~= nil then
			for Rank, Data in ipairs(page) do
				local UserId, Value = Data.key, Data.value
				local Name = GetNameFromUserId(UserId)
				if UserId ~= nil and Value ~= nil and Name ~= nil then
					if tonumber(Rank) == 1 then
						self:UpdateNumber1Player(leaderboardName, Name, UserId)
						if start == false then
							self:GiveTrophyPetToPlayer(Name)
						end
					end
					cloneUI(leaderboardName, Rank, Name, Value, parent)
				end
			end
		end
	end
end

function LeaderboardService:SetLeaderboardData(plr)
	if notOnLeaderboards[plr.UserId] == true or notOnLeaderboards[plr.Name] == true then else
		for _, v in pairs(leaderboardsFol:GetChildren()) do
			if v:IsA("Model") then
				local leaderboardName = v.Name
				local set, fail = pcall(function()
					local data = getDataStore(leaderboardName)
					if data ~= nil then
						local amount, divTrue = getValForDataSet(plr, leaderboardName)
						if amount ~= nil and type(tonumber(amount)) == "number" then
							if tonumber(amount) > 0 then
								if divTrue == true then
									local divAmount = divider
									if leaderboardName == "Rebirths" then
										divAmount = rebirthDivider
									end
									local setAmount = Round_Function(tonumber(amount))
									local newAmount = setAmount / divAmount
									newAmount = Round_Function(tonumber(newAmount))
									data:SetAsync(plr.UserId, tonumber(newAmount))
								else
									local setAmount = Round_Function(tonumber(amount))
									data:SetAsync(plr.UserId, tonumber(setAmount))
								end
							end
						else
							errorMsg("The Amount To Set for the DataStore was nil or not a number", leaderboardName, plr.Name) 
						end
					else
						errorMsg("DataStore was nil or not a DataStore", leaderboardName, plr.Name) 	
					end
				end)
				if fail and not set then 
					errorMsg(fail, leaderboardName, plr.Name) 
				end 
				wait(1)
			end
		end
	end
end

function LeaderboardService:LoadAnimations()
	spawn(function()
		for _, invisibleBox in pairs(InvisibleBoxes:GetDescendants()) do
			if invisibleBox:IsA("BasePart") then
				invisibleBox.Transparency, invisibleBox.CanCollide = 1, true
			end
		end
		for _, npc in pairs(NPCS:GetChildren()) do
			local anim = npc:FindFirstChildWhichIsA("Animation")
			if anim ~= nil then
				local humanoid = npc:FindFirstChild("Humanoid")
				if humanoid ~= nil then
					local animLoaded = humanoid:LoadAnimation(anim)
					animLoaded:Play()
				end
			end
		end
	end)
end

function LeaderboardService:StartLeaderboards(start)
	local function updateLeaderboard()
		for leaderboardName, leaderboard in pairs(leaderboards) do
			if leaderboard:FindFirstChild("Board") ~= nil then
				if leaderboard:FindFirstChild("Board"):FindFirstChild("SurfaceGui") ~= nil then
					local frameParent = leaderboard.Board.SurfaceGui.ScrollingFrame

					for _, v in pairs(frameParent:GetChildren()) do
						if v:IsA("Frame") or v:IsA("ImageLabel") or v:IsA("ImageButton") then
							v:Destroy()
						end
					end
					local data = getDataStore(leaderboardName)
					if data ~= nil then
						self:UpdateLeaderboard(leaderboardName, data, frameParent, start) wait()
					else
						warn(leaderboardName.." does not have a DataStore!")
					end
				else	
					warn(leaderboardName.." does not have a leaderboard gui inside!")
				end
			else
				warn(leaderboardName.." does not have a board inside!")
			end
		end
	end
	if start == true then
		self:LoadAnimations()
		updateLeaderboard()
	else
		for _, plr in pairs(players:GetPlayers()) do
			self:SetLeaderboardData(plr)
		end
		updateLeaderboard()
	end
end

function LeaderboardService:CanRun()
	return CAN_RUN_MODULE
end

function LeaderboardService:Initialize()
	spawn(function()
		self:StartLeaderboards(true) wait(1)
		while true do
			wait(UPDATE_TIME)
			spawn(function()
				self:StartLeaderboards(false)
			end)
			local numOfPlrs = #players:GetPlayers()
			wait(5 + (numOfPlrs * waitTimePerLeaderboard))

			UpdateServerMessage += 1
			if UpdateServerMessage >= 2 then
				UpdateServerMessage = 0
				ServerChatMessagesModule:SpeakMessage(nil, nil)
			end

			UpdateGoalsCounter += 1
			
			if UpdateGoalsCounter >= 6 then
				UpdateGoalsCounter = 0
				
				CommunityGoalsModule:SetBoard()
			end
		end
	end)
end

return LeaderboardService

please help me to fix this problem ASAP.

1 Like

Could you put ``` around your script so that it is easier to read?

Here are some steps you can take to make this work:

  • Modify your data handling functions to work with strings or arrays of smaller numbers.
  • Implement functions for arithmetic operations (addition, subtraction, multiplication, division) on these custom data types.
  • Update your leaderboard display functions to handle these custom data types and display them correctly.
1 Like

can you do this because it’s complicated for me

The suggestion made by @jasper53682 is the proper way to achieve this.
If you want to skip implementing this yourself, consider using pre-existing modules like Kdude’s InfiniteMath

You could save it as a string value instead, and whenever you need to change it, make it a number. I’m not sure what the limit on arithmetic is in script though.

You can do what everyone suggested above or you could use

Scientific Notation


It’s the stuff you see like:

1e

I’m pretty sure this isn’t a valid scientific notation, I think a better example would be:

9.223e+18

1 Like

I am not able to do this at the moment, but could always watch tutorials on how to implement strings into scripts.