For loops don't execute

The first for loop execute , but the secound not. I’m new in for loops, so please help me.
``

game.ReplicatedStorage.SelectedPiggy.Changed:Connect(function()

				wait(0.4)
		
				for i = 1,0,-.25 do  --this execute
				script.Parent.Fade.BackgroundTransparency = i
                print("screen go to black") --prints
				wait(0.1)
				end
		
		
				for i = 1,0,-.3 do --this don't execute
				script.Parent.Fade.BackgroundTransparency = i --The screen go from black to transparent. (not works)
                print("screen back to normal") -don't print
				wait(0.3)
				end
		
	end)``

You should use TweenService. Here is an example with your code:

local ts = game:GetService("TweenService")
wait(0.4)
local t1 = ts:Create(script.Parent.Fade, TweenInfo.new(0.4), {BackgroundTransparency = 0}
t1:Play()
t1.Completed:Wait()

local t1 = ts:Create(script.Parent.Fade, TweenInfo.new(0.3), {BackgroundTransparency = 1}
t1:Play()
t1.Completed:Wait()

end)

I think it didn’t complete because 1 cannot be divided equally by 0.3. I am not so sure since I don’t use for loops with number iterators that much.

Good luck!

2 Likes

I don’t get why you would certainly want to set the BackgroundTransparency of the object to a value lesser than 0.