Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My local script that uses "for i" doesn't seem to work?

This is a local script that uses the function "for i" to change transparency. It does not work, it does not even show any errors in output or script analysis. Help!

Here is the script:

local gui = script.Parent
local frame = gui.Frame
local warning = frame.Warning
warning.ImageTransparency = 1

while true do
	wait()

for i = 0, 1, 0.1 do
	warning.ImageTransparency = i
end
	wait()
for i = 1, 0, 0.1 do
	warning.ImageTransparency = i
end

end

2 comments

0

Does the image remain transparent or is it not transparent at all once this script runs

0

It is not transparent until the script runs.

1 answer

✓ Accepted answer

Your script is mostly working, but it's doing its job very quickly.

It assigns transparency to 0, then 0.1, then 0.2, then 0.3, then 0.4, then 0.5, ...., then 1.

But it does all of that without pausing, so you will only be able to see the last assignment.

You need a wait() inside your loop in order to see it.


In order to count backwards, you have to say -0.1 instead of 0.1.


Tab your code correctly -- it makes it much easier to figure out which things belong to which loops / conditions.

while true do
	for i = 0, 1, 0.1 do
		warning.ImageTransparency = i
		wait() -- added
	end
	
	for i = 1, 0, -0.1 do -- 0.1 should be -0.1
		warning.ImageTransparency = i
		wait() -- added
	end
end
		

1 comment

0

Thank you! Now I know what to do in the future.

This discussion is preserved as it was. New answers, comments, and votes are closed.