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

How would I make a PointLight fade in and out?

Asked by 7 years ago
Edited 7 years ago

I'm trying to make a fading in and fading out PointLight using it's property Brightness. Seems like a simple question, but I cant quite figure it out. I've tried using for, but it doesn't work. Any help please? Here is the code I've tried using:

for i=1,0,.1 do
script.Parent.PointLight.Brightness = i
end

Also, if someone could give me a little refresher on how to use for loops correctly, that would be awesome!

1 answer

Log in to vote
2
Answered by 7 years ago

When you are trying to loop downwards in a for loop, you need to set the 3rd number as a negative number, otherwise Lua will assume you are trying to count upwards.

You also need to use wait() in the loop so it will actually take times between loops to see the fade.

Lastly, to make it fade in and out, you need to use two for loops in a while loop, so the brightness can go up and down.

while true do --Loops the fade out and fade in
for i = 1,0,-.1 do --Fade out
    script.Parent.PointLight.Brightness = i
    wait()
end
for i = 0,1,.1 do --Fade in
    script.Parent.PointLight.Brightness = i
    wait()
end
wait()
end
0
Thank you so much! PyccknnXakep 1225 — 7y
Ad

Answer this question