Hello! I’ve recently came across an issue with pairing, so let me break it down -
My goal is to make every light ingame to flash red, for this I grabbed the descendants and assorted them via pairing; however this only works for some lights and not all of them. Bellow you will see the script:
for i,v in ipairs(UsedWorkspace) do
if v:IsA("SpotLight") or v:IsA("SurfaceLight") then
v.Color = Color3.new(255,0,0)
end
end
As I previously mentioned, only some lights around different areas turn red whereas others are still the same as they were. I am calling this from a Changed:Connect function used to determine when one of my values ingame are true.
If you have any solutions, let me know - they would be appreciated.
for i, v in ipairs(workspace:GetDescendants()) do
if v:IsA("SpotLight") or v:IsA("SurfaceLight") or v:IsA("PointLight") then
v.Color = Color3.new(1, 0, 0)
end
end
I’ve added an additional “Light” instance type, also bare in mind that Color3.new() can only accept arguments between 0 and 1 inclusively.
Likely the reason that it’s not working for some lights is that you’re only checking for the SpotLight and SurfaceLight class names, you forgot PointLights. Though as a simpler way to do what you wanted in that if statement, you can do v:IsA("Light") and it would do the same since IsA respects inheritance, and those 3 classes all inherit from Light.
And another issue I see is the usage of Color3.new as it accepts a number between 0 and 1 as @Limited_Unique mentioned, you can alternatively use Color3.fromRGB as that accepts between 0 and 255 and can be easier to understand for the most part
My issue isn’t what type of lights are actually being used but the fact that some lights are changed and some are not.
Yeah, well the main issue was the incorrect use of “Color3.new()”, try the script now. I’ve also opted for “workspace:GetDescendants()” it’s slower but it’s just to make sure you’re referencing every “Light” instance in the workspace and not missing any out.
I have tried the .fromRGB string including adding the other light type, however my problem still persists - only some lights are affected by the script whereas others aren’t. Bellow is an example.
Left side is plain, right side is red.
That’s probably because the other properties are different between the “Light” instances, like “Brightness” and “Range” etc.
It’s still an issue - it appears that this problem happens only with this script.
So, here’s the script.
ThreatLevel.Changed:Connect(function()
if ThreatLevel.Value == 5 then
ClientAmbOff:FireAllClients()
Audio.Alarms.LockdownAlarm:Play()
Audio.Misc.Lockdown:Play()
for i,v in pairs(UsedWorkspace) do
if v:IsA("SpotLight") or v:IsA("SurfaceLight") or v:IsA("PointLight") then
v.Color = Color3.fromRGB(255,0,0)
end
end
else
ClientAmbOn:FireAllClients()
Audio.Misc.Lockdown:Stop()
Audio.Alarms.LockdownAlarm:Stop()
game.ReplicatedStorage.Events.ClientAmbOn:FireAllClients()
for Light,ColorS in pairs(LightColors) do
Light.Color = ColorS
end
end
I can see a red dim even in the lights which you considered “plain”. You should equalise all the properties when changing the color, that way you should see a similar effect.
That’s just the default lighting.
Is UsedWorkspace a variable that contains the descendants of Workspace? Maybe try referencing workspace:GetDescendants() directly in the event that the places that don’t have working light are made after the variable is made?
Yes, I use :GetDescendants() for it.
I have already mentioned that in one or two of my own replies to make sure that all the “Light” instances are being referenced.
for i,v in pairs(UsedWorkspace) do
if v:IsA("SpotLight") or v:IsA("SurfaceLight") or v:IsA("PointLight") then
v.Color = Color3.fromRGB(255,0,0)
v.Brightness =
v.Range =
end
end
Try this, you’ll need to set some valid value for both “Brightness” and “Range”.
There is no need for that. As I stated before this is a specific script-only issue, I’ve used my lighting methods in another script that completely worked.