How to make Cash Bar NOT show past the decimal

Hello DevForum Community, I need help for my cash bar script it shows the cash number value but it shows past the decimal. Anyone have a solution for this? script below

`local player = game.Players.LocalPlayer

function comma_value(n)
local left, num, right = string.match(n, ‘^([^%d]%d)(%d)(.-)$’)
return left … (num:reverse():gsub(’(%d%d%d)’, '%1 '):reverse()) … right
end

local leaderstats = player:WaitForChild(“leaderstats”)
local Cash = leaderstats:WaitForChild(“Money”)

if not Cash:IsA(“NumberValue”) and not Cash:IsA(“IntValue”) then
return
end

function UpdateCashTitle(value)
script.Parent.Text = “” … comma_value(value)
end

UpdateCashTitle(Cash.Value)

Cash.Changed:Connect(function()
UpdateCashTitle(Cash.Value)
end)`

made ur code show correctly

local player = game.Players.LocalPlayer

function comma_value(n)
  local left, num, right = string.match(n, ‘^([^%d] *%d)(%d* )(.-)$’)
  return left … (num:reverse():gsub(’(%d%d%d)’, '%1 '):reverse()) … right
end

local leaderstats = player:WaitForChild(“leaderstats”)
local Cash = leaderstats:WaitForChild(“Money”)

if not Cash:IsA(“NumberValue”) and not Cash:IsA(“IntValue”) then
  return
end

function UpdateCashTitle(value)
  script.Parent.Text = “” … comma_value(value)
end

UpdateCashTitle(Cash.Value)

Cash.Changed:Connect(function()
  UpdateCashTitle(Cash.Value)
end)

btw I didn’t make any changes, only made it easier to read for others

1 Like

So one of the options I can think of is using math.ceil or math.floor for your Cash Values.

math.floor meaning your value will round to the lower value whereas math.ceil will round it to the upper value e.g. math.floor(10.5) is equal to 10 whereas math.ceil(10.5) is equal to 11.

Let me know if UpdateCashTitle(math.floor(Cash.Value)) or UpdateCashTitle(math.ceil(Cash.Value)) works for you. Sorry if this was not what you were looking for, update me on how it goes though!

1 Like

Thank you, it works! I appreciate the help! :green_heart:

Before
pic

After
pic 1

1 Like