Pointlight suddenly not enabling

I was working on a Light System which when the power switch is off all lights turn off (basically mall) but before implementing it i decided to test it first however when trying it pointlight doesn’t worked but no errors what so ever in the output nothing

here’s the script

local GreenGo = game.Workspace.GreenGo
local StepMe = game.Workspace.StepMe
local TestLight = game.Workspace.GreenGo.TestLight

function onTouched(part)
	for index, object in next, game.Workspace:GetChildren() do
		if object:IsA('Part') then
			if object.Name == 'GreenGo' then
				object.BrickColor = BrickColor.new('Lime green')
				object.Material = Enum.Material.Neon
			end
		if object:IsA('PointLight') then
				if object.Name == 'Testlight' then
					object.Testlight.Enabled = true
					print ('Testing1')
				end
			end
		end
	end
end

function LightTouched(part)
	for index, object in next, game.Workspace:GetChildren() do
		if object:IsA('PointLight') then
			if object.Name == 'Testlight' then
				object.Testlight.Enabled = true
				print ('Testing1')
			end
		end
	end
end


StepMe.Touched:Connect(onTouched)
StepMe.Touched:Connect(LightTouched)

Some function came from a forum post while other function (Touched:Connect and Part Function) is the ones that im testing with

Thanks in advance!

You’re looping through the children of the workspace but since “TestLight” is a child of “GreenGo” and not a child of the workspace it won’t be detected. You should rather use “:GetDescendants()” when looping through the workspace because the function returns all of the objects in the workspace and not just the children.

The script isn’t detecting the point light because you spelled the name wrong when comparing them. The actual name of the point light is “TestLight” but in the script you put: “Testlight”. That’s why it isn’t working. You could also instead check if the current part you’re looping over is the point light:

if object == TestLight then
     -- Rest of the code here
end

The reason why “:GetChildren()” isn’t detecting “TestLight” is because it essentially gets all parts whose parent property is set to “game.Workspace” but since “TestLight” has its parent property set to “game.Workspace.GreenGo” it won’t get returned by the “:GetChildren()” function.

I always forgot to double check the spelling so thats why i couldn’t see why it didn’t worked because output didn’t tell me about it

but thanks again (and sorry for the dumb reply with the TestLight being spell like that)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.