Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

0

the line that is causing the problem is line 3

0

:WaitForChild() is your best friend, try it

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.