Why does this script not work?

Basically, I have 6 buttons where if you click and meet a certain requirement, they’ll turn from red to green, after they all turn to green, an Orb and the 2 PointLights inside of it should turn from the color red to green, but for some reason when all the 6 buttons are clicked nothing happens? Nothing appears in output either, how do I fix this?

ServerScript in ServerScriptService:

local Orb = game.Workspace.PortalArea.Orb
local OrbLight1 = game.Workspace.PortalArea.Orb.PointLight
local OrbLight2 = game.Workspace.PortalArea.Orb.PointLight2

local Lights = workspace:WaitForChild("Lights"):GetChildren()

local ColorGreen = Color3.fromRGB(0, 255, 0)

local BottomLight = game.Workspace.PortalArea.OrbBottomLight


Lights:GetPropertyChangedSignal("Color"):Connect(function()
	
	if Lights.Color ~= ColorGreen then
		
		Orb.Color = ColorGreen
		OrbLight1.Color = ColorGreen
		OrbLight2.Color = ColorGreen
		
	end 
	
end)
6 Likes

GetChildren returns a table of instance. Use a for loop to get all the instance
Edit: Use Zerin’s way, mine was incorrect

4 Likes

Lights is a table of instances.
You have to go trough them with a for loop like

local greenLights = {}
for _, light in pairs(Lights) do
 if light.Color ~= ColorGreen then
  table.insert(greenLights, light)
 end
end

if #greenLights == #Lights then
 -- all are green
 Orb.Color = ColorGreen
 OrbLight1.Color = ColorGreen
 OrbLight2.Color = ColorGreen
end
5 Likes

For some reason, before I click the parts & they turn from red to green, the Orb is already colored green

2 Likes
for i, light in pairs(Lights) do
	light:GetPropertyChangedSignal("Color"):Connect(function()
	
		local greenLights = {}
	for _, light in pairs(Lights) do
 		if light.Color ~= ColorGreen then
 		 	table.insert(greenLights, light)
 		end
	end

	if #greenLights == #Lights then
 		-- all are green
 	Orb.Color = ColorGreen
 		OrbLight1.Color = ColorGreen
		 OrbLight2.Color = ColorGreen
		end
	end)
end

oops wrong reply

3 Likes

The orb still doesn’t change to green after clicking all 6 Lights (buttons) :cry:

And nothing in output shows either

2 Likes

Where is the script located and what kind of script is it(local script or server script)

3 Likes

Server Script under ServerScriptService (The game is 1-player server)

2 Likes

Can you send a recording of what is happening?

3 Likes

Just to clear some things up, these are under workspace:

Folder containing Orb and it’s PointLights:
RobloxStudioBeta_iUU2ozbyxQ

Folder containing the Lights (buttons):
RobloxStudioBeta_BnNzFR9L6e

Current script used:

local Orb = game.Workspace.PortalArea.Orb
local OrbLight1 = game.Workspace.PortalArea.Orb.PointLight
local OrbLight2 = game.Workspace.PortalArea.Orb.PointLight2
local Bottom = game.Workspace.PortalArea.OrbBottomLight

local Lights = workspace:WaitForChild("Lights"):GetChildren()

local ColorGreen = Color3.fromRGB(0, 255, 0)

local BottomLight = game.Workspace.PortalArea.OrbBottomLight


for i, light in pairs(Lights) do
	light:GetPropertyChangedSignal("Color"):Connect(function()

		local greenLights = {}
		for _, light in pairs(Lights) do
			if light.Color ~= ColorGreen then
				table.insert(greenLights, light)
			end
		end

		if #greenLights == #Lights then
			-- all are green
			Orb.Color = ColorGreen
			OrbLight1.Color = ColorGreen
			OrbLight2.Color = ColorGreen
			Bottom.Color = ColorGreen
		end
	end)
end

Location of the script:
RobloxStudioBeta_NvBBaXx44R

Recording of what’s happening:
robloxapp-20231217-0306485.wmv (1.3 MB)

Basically, the Orb, Orb PointLights, and the bottom part below the orb are supposed to go green after the 6 Lights (buttons) become green.

1 Like
local Orb = game.Workspace.PortalArea.Orb
local OrbLight1 = game.Workspace.PortalArea.Orb.PointLight
local OrbLight2 = game.Workspace.PortalArea.Orb.PointLight2
local Bottom = game.Workspace.PortalArea.OrbBottomLight

local Lights = workspace:WaitForChild("Lights"):GetChildren()

local ColorGreen = Color3.fromRGB(0, 255, 0)

local BottomLight = game.Workspace.PortalArea.OrbBottomLight


for i, light in pairs(Lights) do
	light:GetPropertyChangedSignal("Color"):Connect(function()

		local greenLights = {}
		for _, light in pairs(Lights) do
			if light.Color == ColorGreen then
				table.insert(greenLights, light)
			end
		end

		if #greenLights == #Lights then
			-- all are green
			Orb.Color = ColorGreen
			OrbLight1.Color = ColorGreen
			OrbLight2.Color = ColorGreen
			Bottom.Color = ColorGreen
		end
	end)
end

I made a mistake, I checked if it wasn’t green with ~= instead of using == and checking if it is equal to green.
This should work.

3 Likes

Still doesn’t change the color of the items to green after the buttons are clicked :sob:

Can you try copy and pasting the script again? I forgot to change it lol

1 Like

It’s working perfectly, thank you so much!!! :heart:

1 Like

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