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

How would I make a PointLight fade in and out?

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

✓ Accepted answer

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

1 comment

0

Thank you so much!

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