I'm new to scripting and I'm having some trouble. I want to add a point light into an brick, have it fade to 0 range and brightness, then light itself back up again. How would I make a script that could do this?
Pulsating Point Lights?
1 answer
If you want a continuous loop, it's ideal to use a while loop with some for loops:
while Loop Example
while true do
wait(2)
end
while Loop Composition
while [Argument] do
wait[WaitTime]
end
for Loop Example
for i = 1,10 do
script.Parent.PointLight.Brightness = script.Parent.PointLight.Brightness + .1
script.Parent.PointLight.Range = script.Parent.PointLight.Range + .1
wait(.1)
end
-- You can add a `wait()` here to create a pause between the two loops.
for i = 1,10 do
script.Parent.PointLight.Brightness = script.Parent.PointLight.Brightness - .1
script.Parent.PointLight.Range = script.Parent.PointLight.Range - .1
wait(.1)
end
for Loop Composition
for [Variable] = [StartNumber], [EndNumber], [Increment (Default = 1)] do
wait(WaitTime) -- Optional for a typical 'for' loop, but ideal if you want a visible transition
end
StartNumber - The first run of the loop
Ex. 3: the loop will start at the 3rd run.
EndNumber - The last run of the loop
Ex. 9: the loop will stop after the 9th run.
Increment - Regular increase of the run of the loop by a given number
Ex. 2: the loop will run by 2s (2, 4, 6...).
while & for Loop Combination Example
while true do
for i = 1,10 do -- Increase in Range/Brightness
script.Parent.PointLight.Brightness = script.Parent.PointLight.Brightness + .1
script.Parent.PointLight.Range = script.Parent.PointLight.Range + .1
wait(.1)
end
wait(2)
for i = 1,10 do -- Decrease in Range/Brightness
script.Parent.PointLight.Brightness = script.Parent.PointLight.Brightness - .1
script.Parent.PointLight.Range = script.Parent.PointLight.Range - .1
wait(.1)
end
wait(2)
end
The PointLight will increase brightness and range by .1 every .1 seconds. After each property reaches 1, the process will wait for 2 seconds.
The Pointlight will decrease brightness and range by .1 every .1 seconds. After each property reaches 0, the process will wait for 2 seconds and start all over again.
This discussion is preserved as it was. New answers, comments, and votes are closed.
