So I made a script that while touched, turns the color of all the lights in a game red, and when not touched they turn back to white. This script works perfectly on it's own currently. I would like to make it so that the point lights inside the lights turn red while touched as well, and back to white when not touched. The problem is, the script i made including this doesn't work. I did manage to make a script that does turn the point lights red, but the lights and point lights dont turn back to white after the player stops touching it.
Script with PointLights
local barrier = script.Parent
for index,part in pairs(game.Workspace.lights:GetChildren()) do
if part:IsA("Part") then do
barrier.Touched:connect(function()
part.BrickColor = BrickColor.new("Bright red")
part.PointLight.Color = Color3.new(1, 0, 0)
end)
barrier.TouchEnded:connect(function()
part.BrickColor = BrickColor.new("Institutional white")
part.PointLight.Color = Color3.new(1, 1, 1)
end)
end
end
end
Script without point lights:
local barrier = script.Parent
for index,part in pairs(game.Workspace.lights:GetChildren()) do
if part:IsA("Part") then do
barrier.Touched:connect(function()
part.BrickColor = BrickColor.new("Bright red")
end)
barrier.TouchEnded:connect(function()
part.BrickColor = BrickColor.new("Institutional white")
end)
end
end
end
script that makes the point lights and lights turn red, but not back to white when not touched
local barrier = script.Parent
barrier.Touched:connect(function()
for i, v in pairs(lights:GetChildren()) do
v.BrickColor = BrickColor.new("Bright red")
for index, value in pairs(v:GetChildren()) do
value.Color = Color3.new(1,0.109804, .109804)
end
end
end)
barrier.TouchedEnded:connect(function()
for i, v in pairs(lights:GetChildren()) do
v.BrickColor = BrickColor.new("Institutional white")
for index, value in pairs(v:GetChildren()) do
value.Color = Color3.new(1,1,1)
end
end
end)

1 comment
TouchEnded isn't reliable