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

PointLight is not a valid member of unionoperation even if it is?

Asked by 1 year ago

Hi.

I have experienced the error in the title But it has a PointLight. It keeps registering it's not there.

Here is my code.

function gen.flicker(lightP)
    local info = TweenInfo.new(0.2, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut, 1, false)
    local on = gen.tweenServ:Create(lightP.PointLight, info, {Brightness = 1})
    local off = gen.tweenServ:Create(lightP.PointLight, info, {Brightness = 0})

    off:Play()
    off.Completed:Wait()
    lightP.Material = 'Glass'

    on:Play()
    on.Completed:Wait()
    lightP.Material = 'Neon'

    off:Play()
    off.Completed:Wait()
    lightP.Material = 'Glass'

    on:Play()
    on.Completed:Wait()
    lightP.Material = 'Neon'

    off:Play()
    off.Completed:Wait()
    lightP.Material = 'Glass'

    on:Play()
    on.Completed:Wait()
    lightP.Material = 'Neon'
end

function gen.blackout(room)
    local lamps = room.Assets.Lamps:GetChildren()
    for _, lamp in ipairs(lamps) do
        for _, obj in ipairs(lamp:GetChildren()) do
            if obj.Name == 'Shade' then
                task.spawn(function()
                    gen.flicker(obj)
                end)
            end
        end
    end
end
0
the line that is causing the problem is line 3 Sj0ppiedep0ppie -5 — 1y
0
:WaitForChild() is your best friend, try it RainDroutz 23 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

Maybe you either changed the name of it or you're using it in the Client. Try using :FindFirstChildOfClass() or :FindFirstChildWhichIsA() which searches for a child that has the same class name in the given argument regardless of its name. If you're using it in the Client, try making a custom waitForChildWhichIsA() function.

local function waitForChildWhichIsA(parent, className)
    local child

    repeat
        task.wait()
        child = parent:FindFirstChildWhichIsA(className)
    until child ~= nil

    return child
end

function gen.flicker(lightP)
    local PointLight = waitForChildWhichIsA(lightP, "PointLight")
    local info = TweenInfo.new(0.2, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut, 1, false)
    local on = gen.tweenServ:Create(PointLight, info, {Brightness = 1})
    local off = gen.tweenServ:Create(PointLight, info, {Brightness = 0})

    off:Play()
    off.Completed:Wait()
    lightP.Material = Enum.Material.Glass

    on:Play()
    on.Completed:Wait()
    lightP.Material = Enum.Material.Neon

    off:Play()
    off.Completed:Wait()
    lightP.Material = Enum.Material.Glass

    on:Play()
    on.Completed:Wait()
    lightP.Material = Enum.Material.Neon

    off:Play()
    off.Completed:Wait()
    lightP.Material = Enum.Material.Glass

    on:Play()
    on.Completed:Wait()
    lightP.Material = Enum.Material.Neon
end

function gen.blackout(room)
    local lamps = room:WaitForChild("Assets").Lamps:GetChildren()
    for _, lamp in ipairs(lamps) do
        for _, obj in ipairs(lamp:GetChildren()) do
            if obj.Name == "Shade" then
                task.spawn(function()
                    gen.flicker(obj)
                end)
            end
        end
    end
end
Ad

Answer this question