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:
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)
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