How can I fix this script?

So the problem is trying to make the screen fade to white with this script and when I tried it I did not see any changes on the screen and when I check output it did not give any errors.The script is a local script and the script is the child of the frame and the screen GUI is above that. Which is then located in StarterGui.

local function fade()
	for i = 1,0.1,0.1 do
		script.Parent.BackgroundTransparency = i
		wait(i)
	end
end
game.Workspace.Portal_Lv6.Touched:Connect(fade)
1 Like

Maybe fire a remote event to whoever touches the part and start the fading?

Since you’re decreasing in value, you’ll need a negative increment. So, you would write for i = 1,0.1,-0.1 do for that line.

1 Like

For loops are supposed to work like this

for i = [start], [end], [increment] do

So looking at your script, It’ll start at 1, end at 0.1, and increment at a rate of 0.1.

Your problem lies at roblox not continuing for loops if (increment is positive) and end is less then count. or if (increment is negative) and end is greater then the count.

As @LongingBball6805 stated you’ll want to just swap the last number to a negative.

for i = 1, 0.1, -0.1 do

end

I recommend taking a look at TweenService, as it is an easier and optimized way of doing this kind of thing.

If you want a smoother fade then I would suggest taking a look at TweenService

1 Like

You should use TweenService to make this nicely and smoothly. Check it out here if you consider doing so.

I will try for loops again if it does not look good I will use tweenservice
EDIT:It works maybe I need to start double checking my code more often and look for tiny errors like this