Value resets to a very low number when value increases high enough

Ye that’s good but mine u can choose where is the start so it’s full customisation but urs it’s like mine but the starting num is always after 3 like
100
100,000
100,000,000

But mine
1 | “A”
100 | “B”
1000 | “C”

1 Like

I don’t have a module that formats the number. I have this as the script in leaderstats before.

game.Players.PlayerAdded:Connect(function(player)
	while wait() do
		local number =  player.leaderstats.Interactions.Value -- change this to your currency
		local abreviated = player.leaderstats:WaitForChild("Money")




		local abbriviation = {
			K = 4, -- Thousand
			M = 7, -- Million
			B = 10, -- Billion
			T = 13, -- Trillion
			Qa = 16, -- Quadrillion
			Qi = 19, -- Quintillion
			Si = 22, -- Sextillion
			Sp = 25, -- Septillion
			Oc = 28, -- Octillion
			No = 31, -- Nonillion
			Dc = 34, -- Decillion
			Udc = 37, -- Undecillion
			Ddc = 40,
			Tdc = 43,
			Qadc = 46
		}   


		local text = tostring(math.floor(number))

		local chosenAbbriviation

		for abbriviation, digits in pairs(abbriviation) do
			if #text >= digits and #text < (digits + 3) then
				chosenAbbriviation = abbriviation
				break
			end
		end

		if chosenAbbriviation then
			local digits = abbriviation[chosenAbbriviation]

			local rounded = math.floor(number / 10 ^ (digits - 2)) * 10 ^ (digits - 2)

			text = string.format("%.1f", rounded / 10 ^ (digits - 1)) .. chosenAbbriviation
		else
			text = number
		end



		abreviated.Value = text
	end
end)

This was from another forum. The last 4 don’t work because I made them.

This is the script I use, if it helps:

function module.abbreviate(number:number,roundingPrecision:number):string
	roundingPrecision = roundingPrecision or 10
	
	local units = {"","K","M","B","T","Qd","Qn","Sx","Sp","Oc","No","De"}
	local unitIndex = 1
	
	if not (type(number) == "number") then
		warn("Not a number")
		return
	end
	
	while number >= 1000 do
		number /= 1000
		unitIndex += 1
	end
	
	local unit = units[unitIndex]
	if unit then
		return math.floor(number * roundingPrecision) / roundingPrecision .. unit
	else
		warn("Not on units list")
	end
end

Okay.

You should split that off into it’s own module.

What’s the error, though? You said

what exactly did you mean by that? Two things,

  1. I can’t help if you don’t give the error
  2. The way you phrased it made it sound like you were using mine, which is fine but was confusing since mine doesn’t error like that
1 Like

The error was for the one you sent me. Not the past one.

Alright. I’ll try it. I’ll post you the results.

1 Like

Now I’m even more confused, my script works perfectly fine. Did you put it in a ModuleScript?

It doesn’t really matter since mine was made in a rush and is slightly slower (0.02 seconds slower) so you might as well use the one made by @ys3741 unless I can optimize mine, though.

1 Like

So, I’m a little bit confused on how the system works. So I made this script and it gave me an error.


Here’s what I wrote.

while wait() do
		local number =  player.leaderstats:WaitForChild("Interactions") -- change this to your currency
		local abreviated = player.leaderstats:WaitForChild("Money")
		local abrivatemodule = require(game.ReplicatedStorage.AbbrivationModule)

		abrivatemodule.Value = abrivatemodule.abbreviate(number.Value, number.Value)
	end

Note that the roundingPrecision parameter lets you decide how much it should be rounded. For example, a roundingPrecision of 1 would round to the whole number, so 14.62 would be 14, and 1900 (1.9K) would be 1K. A roundingPrecision of 10 would floor to the first decimal, so 14.62 would be 14.6 and 1900 would be 1.9K. If the roundingPrecision is 100, the function will round to the second decimal, and so on. Also, when I say “round”, I mean floor. You can change it to math.round() if you want.

That’s because the number is too big. You need to add more units to the list.

Okay, so I didn’t get an error but I got repeated this error many times.
Screenshot 2025-04-07 182747

while wait() do
		local number =  player.leaderstats:WaitForChild("Interactions") -- change this to your currency
		local abreviated = player.leaderstats:WaitForChild("Money")
		local abrivatemodule = require(game.ReplicatedStorage.AbbrivationModule)

		abrivatemodule.Value = abrivatemodule.abbreviate(number.Value, 1)
	end

Looking at his code, add more abbreviations to the list. e.g. after De is UDe.

1 Like

Okay, so I made the script. But it only shows the past saved value and no errors. How do I fix it?
Screenshot 2025-04-07 183534
leaderstats

while wait() do
		local number =  player.leaderstats:WaitForChild("Interactions") -- change this to your currency
		local abreviated = player.leaderstats:WaitForChild("Money")
		local abrivatemodule = require(game.ReplicatedStorage.AbbrivationModule)

		abrivatemodule.Value = abrivatemodule.abbreviate(number.Value, 10)
	end

module

local module = {}

function module.abbreviate(number:number,roundingPrecision:number):string
	roundingPrecision = roundingPrecision or 10

	local units = {"","K","M","B","T","Qd","Qn","Sx","Sp","Oc","No","De","UDe","DDe","TDc","Qt","Qd","Sd","St","Ocdc","Nmdc"}
	local unitIndex = 1

	if not (type(number) == "number") then
		warn("Not a number")
		return
	end

	while number >= 1000 do
		number /= 1000
		unitIndex += 1
	end

	local unit = units[unitIndex]
	if unit then
		return math.floor(number * roundingPrecision) / roundingPrecision .. unit
	else
		warn("Not on units list")
	end
end

return module

What do you mean by past saved value?

Like I made a saving system that saves your progress if you didn’t know.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("SaveLeaderstats")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder", player)
	folder.Name = "leaderstats"
	local points = Instance.new("NumberValue", folder)
	local addups = Instance.new("NumberValue", player)
	local abreviatedpoints = Instance.new("StringValue", player)
	addups.Name = "Addups"
	addups.Parent = folder
	addups.Value = 1
	abreviatedpoints.Name = "Money"
	abreviatedpoints.Value = ""
	abreviatedpoints.Parent = folder
	points.Name = "Interactions"
	points.Value = 0
end)

Players.PlayerAdded:Connect(function(player)
	local Data = nil
	local success, errormessage = pcall(function()
		Data = Saver:GetAsync(tostring(player.UserId))
	end)

	if success then
		if Data then
			for i, v in pairs(Data) do
				player:WaitForChild("leaderstats"):WaitForChild(i).Value = v
			end
		end
	else
		error(errormessage)
	end
end)

local function Save(player)
	local SavedData = {}
	for _, v in pairs(player.leaderstats:GetChildren()) do
		SavedData[v.Name] = v.Value
	end

	local success, errormessage = pcall(function()
		Saver:SetAsync(tostring(player.UserId), SavedData)
	end)
	if not success then
		error(errormessage)
	end
end

Players.PlayerRemoving:Connect(Save)

game:BindToClose(function()
	for _, v in pairs(Players:GetPlayers()) do
		Save(v)
	end
end)

But the value doesn’t change. So that means the module isnt changing the value. But for the whole leaderstats script, it would look like this.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("SaveLeaderstats")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder", player)
	folder.Name = "leaderstats"
	local points = Instance.new("NumberValue", folder)
	local addups = Instance.new("NumberValue", player)
	local abreviatedpoints = Instance.new("StringValue", player)
	addups.Name = "Addups"
	addups.Parent = folder
	addups.Value = 1
	abreviatedpoints.Name = "Money"
	abreviatedpoints.Value = ""
	abreviatedpoints.Parent = folder
	points.Name = "Interactions"
	points.Value = 0
end)

Players.PlayerAdded:Connect(function(player)
	local Data = nil
	local success, errormessage = pcall(function()
		Data = Saver:GetAsync(tostring(player.UserId))
	end)

	if success then
		if Data then
			for i, v in pairs(Data) do
				player:WaitForChild("leaderstats"):WaitForChild(i).Value = v
			end
		end
	else
		error(errormessage)
	end
end)

local function Save(player)
	local SavedData = {}
	for _, v in pairs(player.leaderstats:GetChildren()) do
		SavedData[v.Name] = v.Value
	end

	local success, errormessage = pcall(function()
		Saver:SetAsync(tostring(player.UserId), SavedData)
	end)
	if not success then
		error(errormessage)
	end
end

Players.PlayerRemoving:Connect(Save)

game:BindToClose(function()
	for _, v in pairs(Players:GetPlayers()) do
		Save(v)
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	while wait() do
		local number =  player.leaderstats:WaitForChild("Interactions") -- change this to your currency
		local abreviated = player.leaderstats:WaitForChild("Money")
		local abrivatemodule = require(game.ReplicatedStorage.AbbrivationModule)

		abrivatemodule.Value = abrivatemodule.abbreviate(number.Value, 10)
	end
end)

Oops wait, I made a typo in the value part.
Instead of abrivatemodule.Value, it should be abreviated.Value.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.