Changing all point light colours in workspace

I am trying to make a proximity prompt that cycles through a few colours for all of the point lights in the workspace when you interact with it. As of now I only made it cycle through white and red.

Here is my current script:

local Work = game:GetService("Workspace")
local num = 0


script.Parent.Triggered:Connect(function()
	if num < 2 then
		if num == 0 then
		for i,v in pairs(Work:GetDescendants())do
			v:IsA("PointLight")
			v.Color = Color3.fromRGB{255,255,255}
			end
		elseif num == 1 then
			for i,v in pairs(Work:GetDescendants())do
				v:IsA("PointLight")
				v.Color = Color3.fromRGB{255,0,0}
			end
		end
		num = num+1
	else
		num = 0
	end
end)

Here is the error I receive:

What I assume is happening is that it’s not only looking at the point lights for the colour property, since “fountain (test)” is just a model that I put in that has nothing to do with the lights. I’m fairly new to scripting and I am pretty lost on what I am doing to be honest. If anyone has a clue on how to fix this it would be greatly appreciated.

P.S. This is my first forums post, and I apologize if I didn’t correctly follow all etiquette.

1 Like
for i,v in Work:GetDescendants() do
	if not v:IsA("PointLight") then continue end
	v.Color = if num == 0 then Color3.fromRGB(255,255,255) else Color3.fromRGB(255,0,0)
end
1 Like

This did change the colour of the point lights, and I managed to tweak it to add another colour (thanks for that), but now when num gets to the largest number and gets reset to 0, the lights don’t turn back to white, and I have no clue where to go from here, unless there’s a way to make it go back to the first “if” again after changing num to 0.

Here’s the current script for reference:

local Work = game:GetService("Workspace")
local num = 0


script.Parent.Triggered:Connect(function()
	if num < 3 then
		for i,v in Work:GetDescendants() do
			if not v:IsA("PointLight") then continue end
			v.Color = if num == 0 then Color3.fromRGB(255,255,255) elseif num == 1 then Color3.fromRGB(255,0,0) else Color3.fromRGB(0,255,0)
		end
		num = num+1
		print(num)
	else
		num = 0
	end
end)
1 Like
script.Parent.Triggered:Connect(function()
	if num > 3 then
		num = 0
	end

   for i,v in Work:GetDescendants() do
		if not v:IsA("PointLight") then continue end
		v.Color = if num == 0 then Color3.fromRGB(255,255,255) elseif num == 1 then Color3.fromRGB(255,0,0) else Color3.fromRGB(0,255,0)
	end

	num += 1
end)
2 Likes

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