Help with my cash gui

I was making a cash gui and it works, kinda. When I get 10k cash, it shows 0.0 k, when i get 12.6k, it shows 2.6k etc. It is just cutting out the first digit. What is wrong with my code?

plr = script.Parent.Parent.Parent.Parent
stat = plr:WaitForChild(“leaderstats”) --Put your leaderstats name

function addComas(str)
return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", “%1,”):reverse():sub(2) or str:reverse():gsub("%d%d%d", “%1,”):reverse()
end

while true do
script.Parent.Text = "$ "…addComas(tostring(stat.Cash.Value)) — Where cash is put your cash name
wait(.1)
end

If you want to see for yourself here is the link:
Beach Hotel Tycoon🐚🏖️ ☀️🌴Beach House Tycoon - RobloxPreformatted text

1 Like

It’s really hard to look at your code unformatted, fortunately for you, I have a video covering abbreviations on a GUI you could check out:

1 Like

I think it’s cause your concatenating with 3 periods…

You should do:

"testString".. "1"

Don’t do:

"testString"... "1"
1 Like

ok i will try that thanks (:smile: Thanks

1 Like

Where is this in the code I dont see it

In the code It has 2 dots but when I paste it in it has 3. What is going on?!?

1 Like

Just replace it with 2 dots

char limit

what is the variable plr do and were it is located

1 Like

it’s because you haven’t formatted your code

put ``` at the top and bottom of your code

anyways try one of these functions

1 Like

What are these scripts for and where would I use them

1 Like

here i wrote this for you:

local plr = game.Players.LocalPlayer
local stat = plr:WaitForChild("leaderstats"):WaitForChild("Cash") -- Your stat

local suffixes = {"K", "M", "B", "T", "Q"}

function roundNumber(number)
	local finalNr = math.floor((((number/1000^(math.floor(math.log(number, 1e3))))*100)+0.5)) /100 .. (suffixes[math.floor(math.log(number, 1e3))] or "")
	return finalNr
end

stat:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = "$ "..roundNumber(stat.Value)
end)

script.Parent.Text = "$ "..roundNumber(stat.Value)

Please mark my reply as solution if it worked!

Try


function addComas(str)
return str:reverse():gsub("(%d%d%d)", “%1,”):reverse():sub(2)
end```