How do i make number have commas each 3 number

local textLabelNumber = script.parent
textLabelNumber.BackgroundColor3 = script.Parent.Parent.Color.Value

textLabelNumber .Parent.Color:GetPropertyChangedSignal("Value"):Connect(function()
	textLabelNumber .BackgroundColor3 = textLabelNumber .Parent.Color.Value
end)

this textlabel is for my leaderboard mount of coins, how do i make textLabelNumber text if has 3 numbers, it will have commas like 1,000

ive tried searching how to use ambrivent number but still no comma

What solutions have you tried so far? Did you look for solutions on the Developer Hub?

You were literally prompted with this question right when you started creating this thread.

Please search for a solution first before posting for help.
This was all the sources I found within 5 minutes of searching.

https://devforum.roblox.com/search?context=topic&context_id=808398&q=commas%20number&skip_context=true

yes tve tried it look like this

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

script.Parent.BackgroundColor3 = script.Parent.Parent.Color.Value

script.Parent.Parent.Color:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.BackgroundColor3 = script.Parent.Parent.Color.Value
end)

still didnt work

You never actually use the function in this block of code, unless I’ve misunderstood

srry im not a pro grammer, so how do i make it work on it

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

script.Parent.BackgroundColor3 = script.Parent.Parent.Color.Value

script.Parent.Parent.Color:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = comma_value(script.Parent.Parent.Color.Value) -- call the function here
    -- (assuming script.Parent is the text label)
	script.Parent.BackgroundColor3 = script.Parent.Parent.Color.Value
end)

@Polygonizised


theres smth wrong with the k, it has a red line underneath it

Just put local k = nil underneath local formatted = amount. The line is just a warning that k has a global variable declaration

1 Like