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

How Do I Make A Light Increase and Decrease More Efficiently?

Asked by 5 years ago
01local light = script.Parent.PointLight
02 
03while true do
04    light.Brightness = 2
05    wait(.1)
06    light.Brightness = 2.2
07    wait(.1)
08    light.Brightness = 2.4
09    wait(.1)
10    light.Brightness = 2.6
11    wait(.1)
12    light.Brightness = 2.8
13    wait(.1)
14    light.Brightness = 3
15    wait(.1)
View all 66 lines...

3 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Use tweening.

A) It'll produce smoother results

B) It can be reversed

C) Way more concise

01local tween_service = game:GetService("TweenService")
02 
03local light = script.Parent.PointLight
04 
05local tween_info = TweenInfo.new(
06    1,   -- time
07    Enum.EasingStyle.Linear, -- easingstyle
08    Enum.EasingDirection.Out, -- easingdirection
09    100, -- repeats (should probably go higher for infinite loop)
10    true -- the magic parameter to make it reverse
11-- you can tweak these settings of course (see wiki links below for help)
12 
13 
14local light_tween = tween_service:Create(light, tween_info, {Brightness = 5})
15light_tween:Play()

TweenService TweenInfo

0
Before I discovered this, I used for loops. I still am not quite familiar with the tween syntax. User#24228 0 — 5y
0
Before I discovered this, I used for loops. I still am not quite familiar with the tween syntax. User#24228 0 — 5y
0
TweenService:Create is a very simple function really. Look through the Wiki page, but the example program at the bottom might be most helpful to you: https://developer.roblox.com/en-us/api-reference/function/TweenService/Create LukeSmasher 619 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Well you could just make a loop that changes the brightness by 0.2 each time.

01local light = script.Parent.PointLight
02 
03while true do
04    wait(0.001)
05    local light = script.Parent.PointLight
06 
07-------------------------------------------------------------------
08 
09    local currentBrightness = light.Brightness
10    wait(0.1)
11    currentBrightness = currentBrightness + 0.2
12end

If this solved your question please accept this answer.

0
that wouldn't work because it would just continually increase the brightness and not decrease it at any given point SKOSHILOKI 67 — 5y
0
Oh yeah i forgot to add decrease... PrismaticFruits 842 — 5y
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01while wait(0.1) do
02    for i = 2,5,0.2 do
03        script.Parent.PointLight.Brightness = i
04        wait(0.1)
05    end
06    for i = 5,2,-0.2 do
07        script.Parent.PointLight.Brightness = i
08        wait(0.1)
09    end
10end
0
works perfectly WaterlooBuilder 4 — 5y

Answer this question