What is wrong with my light effect script, or is this a bug on Roblox's end?

I’m working on a game where a player is trapped in a sinking ship, and at one point in the game I am gonna have them enter a room and the power goes out for a few seconds. So far the script seems to work fine, but then the power comes back on and my games lighting looks wonky as if the brightness of the lights was turned up. Here is a video of it occuring you’ll notice everything is way too bright when the lights come on robloxapp-20200725-1115475.wmv (3.2 MB) I checked the properties of the lights themselves and their brightness hasn’t been altered, I don’t see anything that would be wrong as you’ll see all my script changes in terms of the lights is whether or not their enabled, and the material of them. I can’t find any solutions anywhere and I have no clue what could be causing this, my best guess is if it’s my fault it would have to be somewhere in the code, which you can see here

Light1 = script.Parent.Parent.L1
Light2 = script.Parent.Parent.L2
Light3 = script.Parent.Parent.L3
Light4 = script.Parent.Parent.L4
Light5 = script.Parent.Parent.L5
Light6 = script.Parent.Parent.L6
Light7 = script.Parent.Parent.L7
local buttonPressed = false


script.Parent.Touched:Connect(function(hit)
	if not buttonPressed then
		
	buttonPressed = true
		
	Light1.Bulb.PointLight.Enabled = false
	Light2.Bulb.PointLight.Enabled = false
	Light3.Bulb.PointLight.Enabled = false
	Light4.Bulb.PointLight.Enabled = false
	Light5.Bulb.PointLight.Enabled = false
	Light6.Bulb.PointLight.Enabled = false
	Light7.Bulb.PointLight.Enabled = false
	Light1.Light.Material = "Marble"
	Light2.Light.Material = "Marble"
	Light3.Light.Material = "Marble"
	Light4.Light.Material = "Marble"
	Light5.Light.Material = "Marble"
	Light6.Light.Material = "Marble"
	Light7.Light.Material = "Marble"
	game.Lighting.OutdoorAmbient = Color3.new(0,0,0)
	game.Workspace.PD:Play()
	wait(game.Workspace.PD.TimeLength)
	Light1.Bulb.PointLight.Enabled = true
	Light2.Bulb.PointLight.Enabled = true
	Light3.Bulb.PointLight.Enabled = true
	Light4.Bulb.PointLight.Enabled = true
	Light5.Bulb.PointLight.Enabled = true
	Light6.Bulb.PointLight.Enabled = true
	Light7.Bulb.PointLight.Enabled = true
	Light1.Light.Material = "Neon"
	Light2.Light.Material = "Neon"
	Light3.Light.Material = "Neon"
	Light4.Light.Material = "Neon"
	Light5.Light.Material = "Neon"
	Light6.Light.Material = "Neon"
	Light7.Light.Material = "Neon"
	game.Lighting.OutdoorAmbient = Color3.new(143,143,143)
	game.Workspace.PU:Play()	
		wait(.1)
		script.Parent:Destroy()
		buttonPressed = false
	end
	
end)

Thank you for reading, any help will be much appreciated

1 Like

Before I even start working on helping with the lighting, this code needs some serious reformatting. You can do this by using for loops and concatenating the index, like so:

local grandparent = script.Parent.Parent
local lightArray = {}
local buttonPressed = false

for count = 1, 7 do
    table.insert(lightArray, count, grandparent:FindFirstChild("L" .. count))
end

script.Parent.Touched:Connect(function(hit)
    if buttonPressed then return end
		
    buttonPressed = true

    for i, light in pairs(lightArray) do
        light.Bulb.PointLight.Enabled = false
        light.Light.Material = "Marble"
    end

    game.Lighting.OutdoorAmbient = Color3.new(0,0,0)
    game.Workspace.PD:Play()
    wait(game.Workspace.PD.TimeLength)

    for i, light in pairs(lightArray) do
        light.Bulb.PointLight.Enabled = true
        light.Light.Material = "Neon"
    end

    game.Lighting.OutdoorAmbient = Color3.new(143,143,143)
    game.Workspace.PU:Play()	
    wait(.1)
    script.Parent:Destroy()

    buttonPressed = false
end)

Also, please, name your variables something descriptive! From your code, I can see that each lights hierarchy looks something like:

Light1
L  Bulb
    L  PointLight
L  Light

What is the second light supposed to be?

1 Like

The bulb has the pointlight but it is the glass that surrounds the light, and then the light is a part that is neon to give off the turned on light effect, Sorry about that being not very clear. I’m very inexperienced when it comes to scripting, hence the lackluster code, I replaced mine with your fix up and the lighting still got messed up, so the weird lighting can’t be a problem with the coding right? Here you can see the result is the same with your variation of the code

1 Like

What’s the original material of Light? It’s not Neon, is it?

1 Like

It is indeed Neon, is that bad? I don’t see why a part being neon would cause this big of a problem with the appearance of the room

1 Like

Could you send me all the properties of Light plus the original OutdoorAmbient color?

1 Like

That can’t be. Brightness isn’t being modified in this script.

1 Like

What is the outdoor ambient color before this is run? The only thing that I see that could have caused this is the outdoor ambient color.

Edit: Also, are you sure you don’t have any other scripts influencing things in Lighting or changing the brightness of the lights?

1 Like

The original Outdoor ambient is 143,143,143 the script then changes it to 0,0,0 and then returns it to 143,143,143

1 Like

Which properties do you need specifically of the part named Light?

1 Like

just screenshot all the properties

1 Like

I can’t figure out screenshotting the properties, so I’ll list them off for your I guess,

Color: Institutional White
Cast Shadow = true
Material: Neon
Reflectance and transparency = 0
Anchored archivable and cancollide are all true
and it’s collision fidelity is a box
also it is a meshpart

I’ve checked and none of the scripts in my game other than the one shown above affect lighting, however as you see the script is supposed to set the OutDoorAmbient back to 143,143,143 but for some reason I looked and after the script runs the OutdoorAmbient is set to 36465, 36465, 36465. What could be causing this? The script says nothing about those numbers what so ever.

I just realized what’s wrong: Roblox developer page on Color3. Color3.new() accepts values from 0 to 1 while Color3.fromRGB() accepts values from 0 to 255. Just replace Color3.new with Color3.fromRGB.

2 Likes