Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fade transparency with a for loop?

Asked by
StoIid 364 Moderation Voter
8 years ago
Edited 8 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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
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 Perci1 4988 — 8y
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. GoldenPhysics 474 — 8y
Ad

Answer this question