Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add commas in a IntValue?

Asked by
Vxpper 101
5 years ago

Probably going to get flagged for not constructive but hopefully, I can get an answer.

I want to figure out how to add commas, this script is in a local script through a TextLabel, I'm wanting it to add a comma connected to an IntValue. This is my script which will probably get flagged for it but I have no idea on how to go about doing this.

local plr = game:GetService("Players")
local player = plr.LocalPlayer

while wait(1) do
    script.Parent.Text = "$".. player.RebirthNeeds.Value
end
0
so you mean like instead of 1000000, it would be 1,000,000? hellmatic 1523 — 5y
0
and you should use a Changed event instead of a loop, and wait() should not be a condition User#19524 175 — 5y
0
Can you post the script on how I would do that? Vxpper 101 — 5y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
5 years ago
Edited 5 years ago

Heres one way:

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

--example:
local IntValue = workspace.IntValue

print(addComas(tostring(IntValue.Value))
--the function will only work with a string. You can convert numbers to string using tostring(value)

--You can use the 'Changed' event instead of a loop:
player.RebirthNeeds.Changed:Connect(function()
    script.Parent.Text = "$" .. addComas(tostring(player.RebirthNeeds.Value))
end)
0
Is this all i need to put in the local script, and it will make the RebirthNeeds Value with commas? Vxpper 101 — 5y
0
Also, how do i make it update, when the RebirthNeeds value goes up Vxpper 101 — 5y
0
you can use the Changed event: player.RebirthNeeds.Changed:Connect(function() [code] end) I'll edit my script to show it formatted. hellmatic 1523 — 5y
Ad

Answer this question