Pretty simple question: How do I make the Parent of this script (Which is a transparent Part) turn opaque with steps of 0.1 and a speed of 0.1 seconds.
1 | for i = 1 , 0 , - 0.1 do |
2 | script.Parent.Transparency = (i) |
3 | end |
Your script works fine, the only problem is you aren't waiting! ROBLOX has this nice function named wait which halts the script for the amount of seconds input into the function. This is useful for pauses of all kinds, including the one you want!
1 | for i = 1 , 0 , - 0.1 do |
2 | wait( 0.1 ) |
3 | script.Parent.Transparency = i |
4 | end |
1 | for i = 1 , 10 do |
2 | wait(. 1 ) |
3 | script.Parent.Transparency = script.Parent.Transparency + 0.1 |
4 | end |
This will add 10% transparency to the part every 1/10th of a second
Simple:
1 | for i = 1 , 0 , - 0.1 do |
2 | script.Parent.Transparency = (i) |
3 | wait(. 1 ) |
4 | end |
Or if you mean .1 seconds for the whole thing:
1 | for i = 1 , 0 , - 0.1 do |
2 | script.Parent.Transparency = (i) |
3 | wait( 0.01 ) |
4 | end |
You can calculate the time needed to wait like this. I included nice variables so you can change it up easily.
1 | local speed = 0.1 --Time in seconds |
2 | local stepsize = 0.1 --Step size |
3 | for i = 1 , 0 , - 1 *stepsize do |
4 | script.Parent.Transparency = i |
5 | wait(speed*stepsize) |
6 | end |
If you want a function, here you go:
01 | function animateTransparency(part, seconds, stepsize, endTransparency) |
02 | while part.Transparency ! = endTransparency do |
03 | if part.Transparency < endTransparency then |
04 | if part.Transparency + stepsize > endTransparency then |
05 | part.Transparency = endTransparency |
06 | else |
07 | part.Transparency = part.Transparency + stepsize |
08 | end |
09 | else |
10 | if part.Transparency - stepsize < endTransparency then |
11 | part.Transparency = endTransparency |
12 | else |
13 | part.Transparency = part.Transparency - stepsize |
14 | end |
15 | end |