Formating numbers is not working?

How do i format this script? Im trying to but it’s not working

local player = game.Players.LocalPlayer
local CurrentExp = player:WaitForChild("leaderstats").Exp
local MaxExp = player:WaitForChild("leaderstats").ExpToLevel

local Gui = script.Parent
local Exterior = Gui:WaitForChild("BackFrame")
local label = Gui:WaitForChild("TextLabel")
local Bar = Gui:WaitForChild("Expbar")

local suffixes = {'','K','M','B','T','Qd','Qn'}
local replicatedStorage = game:GetService("ReplicatedStorage")

local function format(val)
	for i=1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
		end
	end
end


script.Parent.TextLabel.Text = format(CurrentExp.Value).."/"..format(MaxExp.Value) --This part isn't working
CurrentExp.Changed:Connect(function()
	script.Parent.TextLabel.Text = CurrentExp.Value.."/"..MaxExp.Value
	if CurrentExp.Value >= MaxExp.Value then
		Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
		wait(0.5)
		CurrentExp.Value = 0
		Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
	else
		Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
	end
end)


It think it’s best if you follow along this tutorial that uses a way to do suffixs/abbreviations. It should work for your thing too regardless if it was made for currency

when i do that it gets a random number the math.random thing

It’s because you’re directly copying from the tutorial instead of seeing what you should do, at the end it shows him converting it into a module script for easy use you can use that and just use the ModuleScript’s function to abbreviate

1 Like

Is there an other video because im quite confused

It’s the simplest one I could find, he explains it quite simply, maybe try watching the full video first without copying any code to understand the process

im kind of understanding it now, but im not sure what to put for local number

He used number as an example, you use your own numbers instead

no like he put math.random, how do i make it not choose a random number?

He used the number thing as an example, you don’t have to take that part of the tutorial, you use your own number variables, aka, CurrentExp.Value and MaxExp.Value

I’m not sure if this will fix it or not. But since all text in a textlabel is a string, try using tostring(CurrentExp.Value), and tostring(MapExp.Value).

What would I put for something like the number part
image
Because I would have two variables

You put your numbers for CurrentExp and MaxExp one by one. It’s not difficult to understand that the number varaible he used is an example

So like (currentexp,MaxExp)???

One by one, you do it twice for both of them

i don’t really understand do you mean this?

function AbbreviateNumber:Abbreviate(CurrentNumber, maxNumber)

Hey there, :wave:

You can check this tutorial by @SirrVenom.