The problem behind your issue, is that your loop doesn’t compensate for the decimal decrementation. The overall iterations of #n will remove a total of n*.1 from n initial: 60-6 = 54. You need to format the loop to subtract from #n by .1 to result in the total number of proper iterations to reach 0.0:
local Seconds = 60
for Second = 60,0,-.1 do
Seconds = Second
print(Second)
wait(.1) end
The issue that is occurring with everyone else’s examples, it that they’re subtracting by i. This parameter is not static, meaning you’ll be subtracting by a number that isn’t in a reliable state; the more i increases, the larger the number subtracted from #n
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local TimeGui = PlayerGui:WaitForChild("TimeGui")
local Seconds = TimeGui:WaitForChild("Seconds")
local TimeText = script.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
for Second = Seconds.Value, 0, -.1 do
Seconds.Value = math.floor(Second*10)/10
TimeText.Text = math.floor(Second*10)/10
wait(.1) end
Character.Humanoid:TakeDamage(100)
A final note: Decreasing by .1 by .1ms will = 1 second, meaning you’re not actually speeding up the counter.
If you don’t have a proper understanding on loops in Lua, I suggest taking a gander at the hyperlink provided, or this simple answer on someones question. Standard for loop syntax goes by Start Stop Step (Optional).
If you try to compare that setup with some answers below, you may understand why they didn’t function properly.
13 comments
What is Time? Is it a number value or what?
Yes, A Number Value
it stops at 54 seconds because as you are adding 1 to 0.1, the 0.1 becomes the 6 second difference after looping,
you can fix it by doing for i = 0.1,seconds.Value,0.1 do
It might help if you actually tell us what seconds.Value initial is, as well as your goal.
Here Is The YT Video Link. Just Modified The Timer So Its More Detailed (25.3 Instead Of 25) https://www.youtube.com/watch?time_continue=72&v=flRfJBP3kdw&feature=emb_logo
I’ve resolved your problem
I did it first ;)
Sure you may have, but you don’t explain the issue, nor are you using efficient practices.
Do you desire you have a number such as 59.9?
yes because the whole game is timed and it should be detailed because it looks cooler. (Im Making A Action Game Where You Have To Get To The End Before The Time Runs Out And Its My First Game Ever)
also, i forgot to mention.. its all about beating high scores so yeah its an important part