Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Countdown GUI help?

Asked by
Zyleak 70
8 years ago

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:

for i=15,0,-0.1 do
    script.Parent.Text = i
    wait(0.1)
 end

3 answers

Log in to vote
0
Answered by 8 years ago

I've had this problem too, except with transparency. Here is what I did.

for i = 0, 1.5, 0.1 do --Start a For loop that goes from 0 to 1.5 using a 0.1 step.
    x = i-1 --If it doesn't work try 1-i --Reverse the number using a variable
    script.Parent.Text = x*10 --Instead of i, use the new variable, x and multiply it by 10 to get an integer.
    wait(1) --wait one second.
end --end the for loop
0
This doesn't seem to work for me. Zyleak 70 — 8y
0
Did you try reversing the i and the 1? Try doing in line 2 x = 1-i I haven't used this code in a while so I wasn't sure which way it was. lightpower26 399 — 8y
Ad
Log in to vote
0
Answered by
drew1017 330 Moderation Voter
8 years ago

Make the GUI use math.floor or math.ceiling. They round up the number to the bottom or top, respectively. Example:

script.Parent.Text = math.floor(i)
0
What is `math.ceiling` or do you mean `math.ceil`? woodengop 1134 — 8y
Log in to vote
0
Answered by 8 years ago

you need to set a Value for it to finish at(Use this code)

wait(10)
timer = Instance.new("ScreenGui")
timer.Name = "countdown"
timer.Parent = game.StarterGui

frame = Instance.new("TextLabel", timer)
frame.Name = "value"
frame.Position = UDim2.new(0, 0, 0)

--Then create two int values on starter and one finish

svalue = Instance.new("IntValue", frame)
svalue.Name = "start"
svalue.Value = 0

evalue = Instance.new("IntValue", frame)
evalue.Name = "end"
evalue.Value = 0
--Here comes he code you can change it to your specs
wait(10)
frame.Text = svalue.Value -1
if svalue.Value <= evalue.Value then
frame:remove()
end


Answer this question