I’m having trouble making my for loop go to 0.
This is my output when i print the index it starts from 1 and I’m wanting it to go to 0 but it goes to a long number.
This is my code.
I’m having trouble making my for loop go to 0.
This is my output when i print the index it starts from 1 and I’m wanting it to go to 0 but it goes to a long number.
This is my code.
This is just one of those things that happens in a lot of languages with floating point math. Floating point math is not precise. I would use print(math.floor(i * 10) / 10)
and see if that goes to 0 and if it does use that (math.floor(i * 10) / 10)
) in place of i
inside the for loop
Just set the “if i == 0 then” to …
if i < 0.1 then
I would recommend using an integer loop variable so that you don’t need to worry about loop variable precision problems (the transparency value will still be imprecise).
for i = 10, 0, -1 do
local textTransparency = i*0.1
RoundLabel.TextTransparency = TextTransparency
RoundNumber.TextTransparency = textTransparency
end
So this works but wym in place of I inside the for loop
like while inside of the for loop, anywhere you normally use i
, use that. I would just save it to a local variable so you don’t do a bunch of math unnecessarily.
Alternatively you can do this
local count = 10
repeat wait(.1)
count = count -1
local i = count /10
--Put Code that happens each time it counts down.
until count <= 0
count = 0
---Put Code that happens when the count reaches 0
This should work perfectly for what you are doing…
hmm I’m tryna think, I would do this but I kind of wanna stick to the for loop cause it looks cleaner
RoundStatus:GetPropertyChangedSigna("Value"):Connect(function()
if RoundFrame.Visible == false then
RoundFrame.Visible = true
end
RoundLabel.TextTransparency = 1
RoundFrame.Position = UDim2.new(0.427, 0, 1.632, 0)
local ii = 10
repeat wait(.1)
ii = ii - 1
RoundLabel.TextTransparency = ii/10
RoundNumber.TextTransparency = ii/10
RoundLabel.TextColor3 = Color3.fromRGB(162, 0, 2)
RoundNumber.TextColor3 = Color3.fromRGB(162, 0, 2)
until ii <= 0
local Tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
local TweenProp = {Position = UDim2.new(.006, 0, 4.164, 0)}
local Tween = TweenService:Create(RoundFrame, TweenInfo, TweenProp)
Tween:Play()
end)
This would be the result in case you have use for it.
Yes, but you still have an i == 0