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
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)