so im making an asym game and i want the timer to quickly tick down to 1:13 within like 2-3 seconds and i got it to tween but while tweening it shows a HUGE decimal on the timer and i tried making the timer constantly round itself but that didn’t change anything.
i forgot to add my current code
local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create(script.Parent.Time, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Value = 73})
Tween:Play()
A trick I’ve used in the past is to tween a NumberValue and connect it’s Changed event to update the visual element to whatever rounded precision I’m looking for. For a timer where you’re only concerned about whole number precision, you could use a IntValue (Value will automatically be rounded to an integer and limit triggers of the Changed event):
local TweenService = game:GetService("TweenService")
local START_DURATION: number = 20
local textLabel = script.Parent.TextLabel
local timerValue = Instance.new("IntValue")
timerValue.Parent = script.Parent
local countdown = TweenService:Create(
timerValue,
TweenInfo.new(START_DURATION, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{Value = 0}
)
timerValue.Changed:Connect(function(value: number)
textLabel.Text = string.format("%i", value)
end)
timerValue.Value = START_DURATION
countdown:Play()
If you want more precision (for example, in the last 10 seconds display tenths of a second) you could set the initial value of the IntValue to 10 times the number of seconds you want the timer to run for. Within the Changed connection, add a condition to determine which style of formatting you want to use.
I just changed the value to an intvalue and it works perfectly.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.