How to make a number goes up / down smoothly?

I use that is it good ?

It still remains with the math.ceil(), which rounds numbers to the highest number possible.
I updated the comment with the newer version that uses math.round().

1 Like

Still not precise if i put 500 sometimes it give me 499 or 501

Script i use :

That’s because whenever Lerping it doesn’t linearnly interpolate until the requested number, or just takes a delay to reach that number. I don’t think I got anything to do with it. Try using TweenService.

how do i use tweenservice in that

and when i change the temperature value it reduce it i don’t want the script to change it

Delete the ‘CurrentNumber’ value.
Insert a new Vector3 value, named it ‘CurrentNumber’, and leave it there.
Test this code and it should work:

local tweenService = (game:GetService("TweenService"));
local runService = (game:GetService("RunService"));

local numberGoal = Instance.new("NumberValue");
numberGoal.Parent = script.Parent
numberGoal.Name = "NumberGoal"

local currentNumber = (script.Parent:WaitForChild("CurrentNumber"));
function TextUpdate()
	tweenService:Create(currentNumber, TweenInfo.new(1), {Value = Vector3.new(numberGoal.Value, 0, 0)}):Play()
end;

numberGoal:GetPropertyChangedSignal("Value"):Connect(TextUpdate)

function Heartbeat(dt)
	script.Parent.Text = math.round(tostring(currentNumber.Value.X))
end;

runService.Heartbeat:Connect(Heartbeat)

Edit: Doesn’t necessarily have to be a Vector3 value, you can use a normal NumberValue, and then tween it’s value. I have no clue why I used Vector3.

1 Like

If you still wanted to use lerping youd just have to change the math for the alpha value a bit

Instead of doing dt * SPEED, you could do

math.clamp((dt * SPEED)/math.abs(numberGoal.Value - currentNumber.Value),0,1)

It gives that
image

Delete the existing CurrentNumber, again.
Reinsert a NumberValue and named it ‘CurrentNumber’.
And use this:

local tweenService = (game:GetService("TweenService"));
local runService = (game:GetService("RunService"));

local numberGoal = Instance.new("NumberValue");
numberGoal.Parent = script.Parent
numberGoal.Name = "NumberGoal"

local currentNumber = (script.Parent:WaitForChild("CurrentNumber"));
function TextUpdate()
	tweenService:Create(currentNumber, TweenInfo.new(1), {Value = numberGoal.Value}):Play()
end;

numberGoal:GetPropertyChangedSignal("Value"):Connect(TextUpdate)

function Heartbeat(dt)
	script.Parent.Text = math.round(tostring(currentNumber.Value))
end;

runService.Heartbeat:Connect(Heartbeat)

It worked fine for me when testing, no matter for what number.

4 Likes

This may interest you, otherwise lerping I guess.

Okay, it works, but now how do i link the script with my temperature value ?

The script should remain where it is.
You have to change the ‘NumberGoal’ value through other scripts (on the Server), and the script will do it’s work.

Yes but it’s the script that create NumberGoal so i don’t know how to change the value

You’d just reference.

workspace[...][...][...].NumberGoal.Value = ?

I did that but when i change the temperature value the text on the screen don’t animate

it only animate when i change number goal

Wait, i managed to make it work

Yes it work now thank you so much

1 Like