Basically I have a GUI which counts down, but when it gets to below 1 (it counts down in 0.1 every 10th of a second) it starts saying like "0.099999999999999". How can i fix this?
Here's the code:
1 | for i = 15 , 0 ,- 0.1 do |
2 | script.Parent.Text = i |
3 | wait( 0.1 ) |
4 | end |
I've had this problem too, except with transparency. Here is what I did.
1 | for i = 0 , 1.5 , 0.1 do --Start a For loop that goes from 0 to 1.5 using a 0.1 step. |
2 | x = i- 1 --If it doesn't work try 1-i --Reverse the number using a variable |
3 | script.Parent.Text = x* 10 --Instead of i, use the new variable, x and multiply it by 10 to get an integer. |
4 | wait( 1 ) --wait one second. |
5 | end --end the for loop |
Make the GUI use math.floor or math.ceiling. They round up the number to the bottom or top, respectively. Example:
1 | script.Parent.Text = math.floor(i) |
you need to set a Value for it to finish at(Use this code)
01 | wait( 10 ) |
02 | timer = Instance.new( "ScreenGui" ) |
03 | timer.Name = "countdown" |
04 | timer.Parent = game.StarterGui |
05 |
06 | frame = Instance.new( "TextLabel" , timer) |
07 | frame.Name = "value" |
08 | frame.Position = UDim 2. new( 0 , 0 , 0 ) |
09 |
10 | --Then create two int values on starter and one finish |
11 |
12 | svalue = Instance.new( "IntValue" , frame) |
13 | svalue.Name = "start" |
14 | svalue.Value = 0 |
15 |