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

How to fade transparency with a for loop?

I forgot how to fade something using a for loop, any help?

This is the code I have so far.

while true do 
	wait()
	for i = 1,10 do 
		wait()
		script.Parent.Tex.Transparency = script.Parent.Tex.Transparency/i
		print(script.Parent.Tex.Transparency)
	end
end

1 answer

✓ Accepted answer

The way you're changing the transparency doesn't make the most sense.

The most reasonable way to fade something from 1 to 0 in 10 steps takes these values:

  • 1
  • 0.9
  • 0.8
  • 0.7
  • 0.6
  • 0.5
  • 0.4
  • 0.3
  • 0.2
  • 0.1
  • 0

What you're doing is... very strange?

Notice that each step just decreases it by 0.1. Do that!

script.Parent.Tex.Transparency = script.Parent.Tex.Transparency - 0.1

2 comments

1

Just to add a bit, I like it as for i = 0, 1, 0.01 do obj.Transparency = i end, which will also work

1

Or you could do "for i = 0, 100 do obj.Transparency = i/100 end". It's generally better to do decimals as late as possible because of floating point errors and other binary/decimal conversion issues. Mostly a best practice thing.

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