Hi! I have been trying to make a script that would grab all lights and fade them out, then change the color, and then fade back in. The issue with the way I am doing it is, they all go one-by-one. I have no idea how to fix this as using this method is the only way I have done in previous ways, so usually I avoid trying to fade anything involving lighting, but I decided I may as well learn something new today.
for level = 100, 0, -1 do
for _, light in ipairs(lights) do
light.Brightness = level/100
end
wait()
end
for _, light in ipairs(lights) do
light.Color = myColor
end
for level = 0, 100 do
for _, light in ipairs(lights) do
light.Brightness = level/100
end
wait()
end
I would suggest using TweenService instead of copying the same line over and over and using wait(). It will make the transition much smoother and can use only one line of code! Here is the documentation for TweenService:Create(): TweenService | Documentation - Roblox Creator Hub
Of course! Tween service implementation here would be great. I was simply fixing the part of his code that he asked to be fixed but improvements are always welcome.
As much as I love all of your replies, and I want to learn many new things, I mainly understand the spawn function mostly, as it seems to be the smallest
@Fire540Games
I have always loved using TweenService, but I am used to using it only on UI, haha.
I believe I understand how it would work with the lights, so I may as well give it a try
Implementing Tween Service may actually be your better bet here although I love coroutines. Try the following:
local object = LightPart.SurfaceLight;
local tweenInfo = TweenInfo.new(0.1);
local changeVal = 0; -- Change to whatever you need it to be at the moment (i.e. 0.8 for highest brightness and 0 for lowest
game:GetService("TweenService"):Create(object, tweenInfo, {Brightness = changeVal}):Play();
Note: you don’t need to redefine those variables. I just added them to help you.