Not changing colors on touch?

Ok so I made a very simple alarm system that detects if your a zombie. and if you are a zombie the hallway lights turn red. but when I try the script the lights don’t turn red but it prints out my name.


local Alarm = script.Parent

local Teams = game:GetService("Teams")
local Lighting = game:GetService("Lighting")
local tService = game:GetService("TweenService")
local lightingRed = Color3.new(script.AlarmColor.Value)
local lightingNormal = Color3.new(95, 97, 97)

local hallwayLights = game.Workspace.Map.Floor1.Main.Light.hallwayLights:GetChildren()
local hallwayColor = Color3.new(255, 255, 255)
Alarm.Touched:Connect(function(hit)
	local human = hit.Parent:WaitForChild("Humanoid")
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	-- debounces
	local ndb = true
	local db = true
	ndb = true
	if player.Team == Teams.Zombie and db == true then
		db = false
		print(hit.Parent.Name.. " is a zombie")
		for i,v in pairs(hallwayLights) do
			hallwayLights.Color3 = Color3.new(0.986755, 0.160571, 0.175555)
		end
		db = true
	else
		for i,v in pairs(hallwayLights) do
			hallwayLights.Color3 = Color3.new(0.985534, 1, 0.999969)
		end
	end
	ndb = false
end)

Does it print out any errors in the output?

No it just print “Remingling is a zombie”

You need to call GetChildren() like so

Also, your debounce flags won’t do anything because they are local to the connect function. Move them outside the connect to have them work across touches.

You’re right the debounces don’t do anything but hallwayLights variable is already getting the children

local hallwayLights = game.Workspace.Map.Floor1.Main.Light.hallwayLights:GetChildren()

so to me it doesn’t look like it would be different but I will try it out.

Are hallwayLights parts or pointLights, surfaceLights, etc.?

Didn’t see that, and it shouldn’t make a difference unless hallwaylights is changing at runtime. Still, better to always reference it directly when doing the iteration.

You probably just need to set a break point and step through your code to see what’s going on. You could add this print… print("part count", #hallwayLights). If that is zero, then it is not finding anything.

They are parts, the lights are inside

This is the entire output

  19:34:59.689  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.689  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.692  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.694  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.695  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.697  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.698  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.699  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.701  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.702  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.704  part count 9 0.986755, 0.160571, 0.175555  -  Server - AlarmScript:22
  19:34:59.806  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.806  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.808  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.810  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.812  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.813  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.815  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.816  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.818  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.819  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.821  part count 9 0.986755, 0.160571, 0.175555  -  Server - AlarmScript:22
  19:34:59.821  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.821  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.823  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.824  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.826  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.827  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.829  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.830  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.832  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.833  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.834  part count 9 0.986755, 0.160571, 0.175555  -  Server - AlarmScript:22
  19:34:59.835  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.835  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.836  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.838  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.839  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.840  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.842  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.843  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.845  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.846  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.848  part count 9 0.986755, 0.160571, 0.175555  -  Server - AlarmScript:22
  19:34:59.848  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.848  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.849  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.850  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.852  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.853  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.854  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.856  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.857  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.859  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.860  part count 9 0.986755, 0.160571, 0.175555  -  Server - AlarmScript:22
  19:34:59.860  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.860  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.862  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.863  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.865  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.866  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.867  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.869  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.870  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.872  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.874  part count 9 0.986755, 0.160571, 0.175555  -  Server - AlarmScript:22
  19:34:59.874  Remingling is a zombie  -  Server - AlarmScript:20
  19:34:59.874  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.875  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.877  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.878  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.879  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.881  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.882  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.884  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.885  part count 9 Part  -  Server - AlarmScript:22
  19:34:59.887  part count 9 0.986755, 0.160571, 0.175555

Try this:

local Alarm = script.Parent

local Teams = game:GetService("Teams")
local Lighting = game:GetService("Lighting")
local tService = game:GetService("TweenService")
local lightingRed = Color3.new(script.AlarmColor.Value)
local lightingNormal = Color3.new(95, 97, 97)

local hallwayLights = game.Workspace.Map.Floor1.Main.Light.hallwayLights:GetChildren()
local hallwayColor = Color3.new(255, 255, 255)
Alarm.Touched:Connect(function(hit)
	local human = hit.Parent:WaitForChild("Humanoid")
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	-- debounces
	local ndb = true
	local db = true
	ndb = true
	if player.Team == Teams.Zombie and db == true then
		db = false
		print(hit.Parent.Name.. " is a zombie")
		for i,v in pairs(hallwayLights) do
			local light = v:FindFirstChildOfClass('Light')
			v.Color = Color3.new(0.986755, 0.160571, 0.175555)
		end
		db = true
	else
		for i,v in pairs(hallwayLights) do
			local light = v:FindFirstChildOfClass('Light')
			v.Color = Color3.new(0.986755, 0.160571, 0.175555)
		end
	end
	ndb = false
end)
1 Like

Oh my god I am so dumb. I couldn’t see that for some reason thank you for the help

No problem. It’s easy to make mistakes like that…

You should try this instead… It has a working db.

local Alarm = script.Parent

local Teams = game:GetService("Teams")
local Lighting = game:GetService("Lighting")
local tService = game:GetService("TweenService")
local lightingRed = Color3.new(script.AlarmColor.Value)
local lightingNormal = Color3.new(95, 97, 97)

local hallwayLights = game.Workspace.Map.Floor1.Main.Light.hallwayLights:GetChildren()
local hallwayColor = Color3.new(255, 255, 255)
Alarm.Touched:Connect(function(hit)
	local human = hit.Parent:WaitForChild("Humanoid")
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	-- debounces
	if player.Team == Teams.Zombie and (not db) then
		db = true
		print(hit.Parent.Name.. " is a zombie")
		for i,v in pairs(hallwayLights) do
			hallwayLights.Color3 = Color3.new(0.986755, 0.160571, 0.175555)
		end
		wait(1) -- change this
		db = false
	else
		if (not db) then
			db = true
			for i,v in pairs(hallwayLights) do
				hallwayLights.Color3 = Color3.new(0.985534, 1, 0.999969)
			end
			wait(1) -- change this
			db = false
		end
	end
end)
1 Like

Thanks for the debounce fix charlimitt