Leaderstats in ScreenGui

How can I put a dot (.) in a money amount in a GUI. If I try script.Parent.Text = plr.leaderstats.Money.Value it says 100000, but can someone help me how to make it 100,000, so a dot in the middle.

image

1 Like
function comma_value(amount)
  local formatted = amount
  while true do  
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end
2 Likes

What means the k, 'cause its got a orange stripe down it. Btw how need i to place it?

local plr = game.Players.LocalPlayer
local Money = plr.leaderstats.Money.Value

function comma_value(amount)
	local formatted = amount
	while true do  
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if (k==0) then
			break
		end
	end
	return formatted
end

Your script is right, just make a white wait loop and put in the function. k is the amount of the value.

local plr = game.Players.LocalPlayer
local Money = plr.leaderstats.Money.Value

function comma_value(amount)
	local formatted = amount
	while true do  
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if (k==0) then
			break
		end
	end
	return formatted
end

while wait(0.01) do
   comma_value(Money)
end

It won’t set dots in it (its in a LocalScript), here is the script now:

local plr = game.Players.LocalPlayer
local Money = plr.leaderstats.Money.Value

function comma_value(amount)
	local formatted = amount
	while true do  
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if (k==0) then
			break
		end
	end
	return formatted
end

while wait(1) do
	comma_value(Money)
	script.Parent.Text = "€ "..Money
end

Try this:

while wait(1) do
   script.Parent.Text = "€"..comma_value(Money)
end
1 Like

It works, thank you for your help, i appreciate it.

1 Like

No problem. :grin:

(This is my first time a person gave me a solution, cause I just joined a few weeks ago :grinning: Thanks)

3 Likes

Do you also know how it keeps updating because when I get a salary it stays at 100,000 instead of 101,000?

1 Like

Is the money value an NumberValue?
If it is. It should, and I suggest you change the wait(1) to wait(0.001)
If it’s not (IntValue), change it to number value.

1 Like

Ah thanks, I already found the problem but thanks again for your help!

2 Likes

Just letting you know that doing a while wait() do loop to update the Label is very bad when it comes to performance. I’d recommend you to update the TextLabel only when the Money value changes, This could be done via:

Money:GetPropertyChangedSignal("Value"):Connect(function()
     -- Code here
end)