Help with NumberValue tween

Hiya,

I’m having a slight problem with tweening a NumberValue. When the value is tweened, it gets from value A to value B but during the transition, but it goes through extremely long decimals which make many things buggy, for instance, the leaderstats and my gui:

There are many more things that break due to this, any solution would be appreciated.

Code

The code that updates the actual value in the leaderstats folder:

MoneyStore:OnUpdate(function(NewMoney)
	TweenService:Create(MoneyValue, TweenInfo.new(1), {Value = NewMoney}):Play()
end)

Code of the cube for context:

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	local Money = DataStore2("Money", Player)
	Money:Increment(15)
end)

Code of the Gui:

Money.Changed:Connect(function(NewValue)
	MoneyLable.Text = "$"..tostring(Money.Value)
end)

I need the value to gradually increase/decrease without going through decimal values.

1 Like

for this, I recommend using math.round which should work pretty well.

MoneyLable.Text = "$"..tostring(math.round(Money.Value))
3 Likes

This only fixes the issue with my GUI but thanks!

Try using “Math.round()” for the GUI that displays the cash amount!

Try changing your “Money” from a Number Value to an Int Value Since Int Value’s can’t hold decimal numbers or floating-point values. Meaning it will be instantly converted into a integer (Whole Number) as the Tween Service Tweens it.

Example:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

    local money = Instance.new("IntValue") --Instead of Instance.new("NumberValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = leaderstats

end)

1 Like

Instead tweening use lerping, it’s easier and performance better for this case because it don’t need additional propertiess + it’s pure math, then do this, or simply make a loop that will add value:

local target = 50 -- value to achieve
local current = player.Money.Value -- current value

local toAdd = target-current



for i = 0,1,0.01 do
local step  = addTo/100
player.Money.Value += step
task.wait(0) -- 1/60 of cooldown soo it will be smooth
end


remember, do this only on client, you should add value constantly on server to avoid bugs