Number Animating

So in many games you will see many he effect I’m looking for here is a video I finally found Pay attention to the global rank see how the number changes that’s what I’m going for and no I didnt just see this video and wanted to create it I have been trying it this for a long time.

I’m not really asking for code just an idea on how to do it

1 Like

You can Tween a NumberValue with TweenService and set part of the text to be the value

1 Like

This would work, lerping would have less of a performance impact and look smoother though.

local Game = game
local Script = script
local RunService = Game:GetService("RunService")
local TextLabel = Script.Parent

local function LerpNumber(StartNumber, EndNumber, Duration)
	local StartTime = RunService.Stepped:Wait()
	while true do
		local CurrentTime = RunService.Stepped:Wait()
		if (CurrentTime - StartTime) > Duration then break end
		TextLabel.Text = math.round((EndNumber - StartNumber) * ((CurrentTime - StartTime) / Duration))
	end
	TextLabel.Text = EndNumber
end

task.wait(5)
LerpNumber(0, 1000, 3)

https://gyazo.com/28011501895963f22a7841453e18c993

3 Likes

ok @Forummer & @KdudeDev I’ll try both and see which best is closer to what was in the video but thank you both!

@KdudeDev when I tween it immediately cuts to the value it doesnt like animate it I don’t know what I’m doing there
@Forummer works great! Is just that when changing it, it restarts from zero and then animates it towards the final number I want it to start from the starting number and then animate to the end number

Never mind lol It was a pretty easy bug to fix

local Game = game
local Script = script
local RunService = Game:GetService("RunService")
local TextLabel = Script.Parent

local function LerpNumber(StartNumber, EndNumber, Duration)
	local StartTime = RunService.Stepped:Wait()
	while true do
		local CurrentTime = RunService.Stepped:Wait()
		if (CurrentTime - StartTime) > Duration then break end
		TextLabel.Text = math.round((EndNumber - StartNumber) * ((CurrentTime - StartTime) / Duration)) + StartNumber -- just added the start number
	end
	TextLabel.Text = EndNumber
end

task.wait(5)
LerpNumber(tonumber(TextLabel.Text), 1000, 3) -- adding the tonumber doesn't fix anything it's just better in the context its being used

My bad, I thought you were lerping from zero so I omitted to add the offset.

1 Like
math.round(StartNumber + (EndNumber - StartNumber) * ((CurrentTime - StartTime) / Duration))

I’d recommend including its addition inside the ‘math.round()’ call (in case the starting value is a decimal value).

1 Like