How would I go about modifying this script so it can have commas when reaching 1,000, 10,000 etc.
I know how to do it normally but not with the tweening included so I need some help please.
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.3)
local label = script.Parent:WaitForChild("BalanceNum")
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local plrStats = plr:WaitForChild("leaderstats")
local plrMoney = plrStats:WaitForChild("Crash")
local tweenNumber = script.Parent:WaitForChild("TweenNumber")
local goal = {}
local function RoundNumber(number)
return(math.floor(number+.5))
end
wait(.5)
label.Text = tostring(plrMoney.Value)
function plrMoneyChanged(value)
goal.Value = value
tweenService:Create(tweenNumber, tweenInfo, {Value = goal.Value}):Play()
tweenNumber.Changed:Connect(function(tweenValue)
local newTweenValue = RoundNumber(tweenValue)
label.Text = tostring(newTweenValue)
end)
end
plrMoney.Changed:Connect(plrMoneyChanged)
number tweening when value increases ^ I want the number tweening but also have commas.
If any of you can help it would be greatly appreciated!
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.3)
local label = script.Parent:WaitForChild("BalanceNum")
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local plrStats = plr:WaitForChild("leaderstats")
local plrMoney = plrStats:WaitForChild("Crash")
local tweenNumber = script.Parent:WaitForChild("TweenNumber")
local goal = {}
local function RoundNumber(number)
return(math.floor(number+.5))
end
wait(.5)
local function AddCommas(value)
local commaString = ""
local valueString = tostring(RoundNumber(value))
local valueKilos = 1
while 10 ^ (valueKilos * 3) < value do
local seperatedKilo = string.sub(valueString, #valueString - 3 * valueKilos + 1, #valueString - 3 * (valueKilos - 1))
commaString = "," .. seperatedKilo .. commaString
valueKilos += 1
end
label.Text = string.sub(valueString, 1, #valueString - 3 * (valueKilos - 1)) .. commaString
end
AddCommas(plrMoney.Value)
function plrMoneyChanged(value)
goal.Value = value
tweenService:Create(tweenNumber, tweenInfo, {Value = goal.Value}):Play()
tweenNumber.Changed:Connect(function(tweenValue)
AddCommas(tweenValue)
end)
end
plrMoney.Changed:Connect(plrMoneyChanged)