Brightness changing script not working

I’m not super good with loops, but I figured I would give them a try, it didn’t work. Alright, so I tried a script that would make the brightness of a PointLight increment by .3, then once it was equal to nine, it would decrease by .3.

Here is my code, it is a Script:

local parent = script.Parent

for 1 == 1 do -- This is a forver loop, right? Idk why it wouldnt be
	while 9 > parent.Brightness do
		parent.Brightness = parent.Brightness+.3
		if 9 < parent.Brightness then
			parent.Brightness = parent.Brightness-.3
		end
	end
end

If you’re looking to increase brightness smoothly, you could use TweenService for this.

local TweenService = game:GetService("TweenService")
TweenService:Create(script.Parent, TweenInfo.new(5), {Brightness = 9}):Play()

You can customize this more by adjusting the TweenInfo, I’ve set most things to default:

As @Ayphic pointed out, you can use tweens to increase the brightness smoothly, also you can take advantage of TweenService:Create() 5th parameter which makes the tween(animation) reverse:

local TweenService = game:GetService("TweenService")

local parent = script.Parent

--wait between each tween, easing animation, easing direction, repeats(infinity), reversing
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, math.huge, true)

local tween = TweenService:Create(parent, info, {Brightness = 9})
tween:Play()

PS: More about TweenService EasingStyle can be found here.

1 Like