Hey there!
I’m trying to use :GetDescendants to tween all point lights in workspace, but it’s not working, and I’m not sure how to get it to work. All help is appreciated!
Here’s my script:
local descendants = workspace:GetDescendants()
for index, descendant in pairs(descendants) do
if descendant:IsA("PointLight") then
local tweenService = game:GetService("TweenService")
local light = descendants
local tweenInfor = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local lightopen = {Color = Color3.new(0.772549, 0, 0)}
local lightclose = {Color = Color3.new(0, 0, 0)}
local lightTween1 = tweenService:Create(light,tweenInfor,lightopen)
local lightTween2 = tweenService:Create(light,tweenInfor,lightclose)
while true do
lightTween1:Play()
wait(2)
lightTween2:Play()
wait(2)
end
end
end
First off, why don’t you just use the reverse boolean in the tween info to reverse your tween instead of having two? Not only would this be more efficient, but it would also solve your problem.
The reason why it isn’t working is most likely because the script infinitely yields at the first light because of the while loop.
while true do
lightTween1:Play()
wait(2)
lightTween2:Play()
wait(2)
end
Like I said, you can make a single tween reverse so you don’t have to do this but if you still want to, make it not yield with coroutine.wrap()
coroutine.wrap(function()
while true do
lightTween1:Play()
wait(2)
lightTween2:Play()
wait(2)
end
end)()
goatmanth90th, you said
local light = descendants --you are defining light as descendants which is all of the things in the workspace
-- I believe that instead you would want to say:
local light = descendant --that way you are tweening that one point light not everything in the workspace, you might have just typoed because they look similar