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 4 years ago
local light = script.Parent.PointLight

while true do
    light.Brightness = 2
    wait(.1)
    light.Brightness = 2.2
    wait(.1)
    light.Brightness = 2.4
    wait(.1)
    light.Brightness = 2.6
    wait(.1)
    light.Brightness = 2.8
    wait(.1)
    light.Brightness = 3
    wait(.1)
    light.Brightness = 3.2
    wait(.1)
    light.Brightness = 3.4
    wait(.1)
    light.Brightness = 3.6
    wait(.1)
    light.Brightness = 3.8
    wait(.1)
    light.Brightness = 4
    wait(.1)
    light.Brightness = 4.2
    wait(.1)
    light.Brightness = 4.4
    wait(.1)
    light.Brightness = 4.6
    wait(.1)
    light.Brightness = 4.8
    wait(.1)
    light.Brightness = 5
    wait(.1)
    light.Brightness = 4.8
    wait(.1)
    light.Brightness = 4.6
    wait(.1)
    light.Brightness = 4.4
    wait(.1)
    light.Brightness = 4.2
    wait(.1)
    light.Brightness = 4
    wait(.1)
    light.Brightness = 3.8
    wait(.1)
    light.Brightness = 3.6
    wait(.1)
    light.Brightness = 3.4
    wait(.1)
    light.Brightness = 3.2
    wait(.1)
    light.Brightness = 3
    wait(.1)
    light.Brightness = 2.8
    wait(.1)
    light.Brightness = 2.6
    wait(.1)
    light.Brightness = 2.4
    wait(.1)
    light.Brightness = 2.2
    wait(.1)
    light.Brightness = 2
    wait(.1)
end

3 answers

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

Use tweening.

A) It'll produce smoother results

B) It can be reversed

C) Way more concise

local tween_service = game:GetService("TweenService")

local light = script.Parent.PointLight

local tween_info = TweenInfo.new(
    1,   -- time 
    Enum.EasingStyle.Linear, -- easingstyle
    Enum.EasingDirection.Out, -- easingdirection
    100, -- repeats (should probably go higher for infinite loop)
    true -- the magic parameter to make it reverse
)  -- you can tweak these settings of course (see wiki links below for help)


local light_tween = tween_service:Create(light, tween_info, {Brightness = 5})
light_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 — 4y
0
Before I discovered this, I used for loops. I still am not quite familiar with the tween syntax. User#24228 0 — 4y
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 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

local light = script.Parent.PointLight

while true do
    wait(0.001)
    local light = script.Parent.PointLight

-------------------------------------------------------------------

    local currentBrightness = light.Brightness
    wait(0.1)
    currentBrightness = currentBrightness + 0.2
end

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 — 4y
0
Oh yeah i forgot to add decrease... PrismaticFruits 842 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
while wait(0.1) do
    for i = 2,5,0.2 do
        script.Parent.PointLight.Brightness = i
        wait(0.1)
    end
    for i = 5,2,-0.2 do
        script.Parent.PointLight.Brightness = i
        wait(0.1)
    end
end
0
works perfectly WaterlooBuilder 4 — 4y

Answer this question