My for loop doesn't reach its goal?

I’m trying to make a fading black screen appear with this code:

local Players = game:GetService("Players")

local HasBegan = RS:WaitForChild("HasBegan")

local Intro = script.Parent

HasBegan:GetPropertyChangedSignal("Value"):Connect(function()
	if HasBegan.Value == false then
		return
	else
		Intro.Visible = true
		for i = 1,0,-0.01 do
			Intro.BackgroundTransparency = i
			print(i)
			wait(0.03)
		end
	end
end) 

It works fine up until the increment reaches around 0.12 after that it breaks and doesn’t completely reach the goal of 0.

Here’s a video of the issue:

I recommend using TweenService instead. Although, if you do want to stick with the loop, just set the UI’s transparency after the loop to end goal.
ex:
game:GetService("TweenService"):Create(Intro,TweenInfo.new(2,Enum.EasingStyle.Linear),{BackgroundTransparency = 0}):Play()

1 Like

It’s just another example of Roblox’s floating point errors. No need to worry. If you wanted to avoid this, you can switch to whole numbers, or do it via the above.

2 Likes

Yeah, I’ll just use Tween as an alternative, thanks for the reply.

That’s really unfortunate for the atmosphere I was going for. Thanks letting me know.

1 Like