i have a issue with a text label inputting numbers like this
local time = script.Parent.Bar.Value.Value
local waittime = script.Parent.Value.Value
if script.Parent.Visible == true then
while wait(0.1) do
time = time - 0.1
script.Parent.Bar.Size = UDim2.new(time / waittime, 0, 1, 0)
script.Parent.Bar.TextLabel.Text = string.format(time.." Seconds Left")
if time <= 0 then
script.Parent.Visible = false
print("finished")
script.Parent.Parent.Parent.Parent.ScreenGui.Finishe.Visible = true
wait(5)
script.Parent.Parent.Parent.Parent.ScreenGui.Finishe.Visible = false
end
end
end
I donβt know if it will change much, but since time is a global function just like print, you may want to change the variable βtimeβ to like βclockβ or something not already defined
local timer = script.Parent.Bar.Value
local waittime = script.Parent.Value
if script.Parent.Visible then
while task.wait(0.1) do
timer.Value = string.format("%0.1f", timer.Value - 1)
script.Parent.Bar.Size = UDim2.fromScale(timer.Value / waittime.Value, 1)
script.Parent.Bar.TextLabel.Text = timer.Value .." Seconds Left"
if timer.Value <= 0 then
script.Parent.Visible = false
print("finished")
script.Parent.Parent.Parent.Parent.ScreenGui.Finishe.Visible = true
task.wait(5)
script.Parent.Parent.Parent.Parent.ScreenGui.Finishe.Visible = false
end
end
end
There are a few problems with your script that I also fixed.
You should be using task.wait instead of wait
You were changing the variable that stored .Value, not the actual .Value.
This takes the number, multiplies it by 10, floors it, then divides it by 10. I had round, but 29.9999 would round to 30. Floor basically truncates the fractional part by returning the biggest integer equal to or smaller than the number you give it.
Adding onto what @Maelstorm_1973 said, you can set it into a function:
local function RoundNumber(number: number, places: number): number
return math.round(number * (10^places)) / (10^places)
end
print(RoundNumber(1/3, 2)) --> prints "0.33"
print(RoundNumber(math.pi, 4)) --> prints "3.1416"
print(RoundNumber(1.4627365728, 1)) --> prints "1.5"
Actually, youβre both wrong. It follows the printf format from C. The correct way is
local text = string.format("%5.1f", timer.Value - 1)
That gives you a total of 5 digits, with one digit to the right of the decimal. The first number is the total space needed. The second number is how much of that is past the decimal point. If that first number is not specified, then itβs whatever the integer part is.