Game messes up when pressed button

this is the script of the button I made to make the game brighter for a local player if he wants to:

script.Parent.MouseButton1Click:Connect(function()
    game.Lighting.Ambient = Color3.new(149, 149, 149)
    end)

at this point, it’s fine. But ofcourse if the player want it back to normal it also needs a button so I made it, and this is the script:

script.Parent.MouseButton1Click:Connect(function()
    game.Lighting.Ambient = (158, 2, 255)
end)

Whenever I press the 2nd button to make it back normal, the whole game messes up and it get super bright I don’t know how to fix this bug.

There is a Color3.new here.

But In here there isn’t. Try putting color3.new in the second script just like you did in the first one.

Color3.new() expects alpha values (percentages between 0 and 1). 149, 149, 149 is automatically clamped down to 1, 1, 1 (white, which is bright). Thus, you should be using Color3.fromRGB() assuming you are using RGB (red, blue, green) values. If HSV (hue, saturation, value), use Color3.fromHSV().

script.Parent.MouseButton1Click:Connect(function()
    game.Lighting.Ambient = Color3.fromRGB(149, 149, 149)
end)
script.Parent.MouseButton1Click:Connect(function()
    game.Lighting.Ambient = Color3.fromRGB(158, 2, 255)
end)

Alternatively you could also use the following:

Color3.new(149/255, 149/255, 149/255)
Color3.new(158/255, 2/255, 255)
2 Likes

The value associated with the “Ambient” property of the “Lighting” service is a Color3 value.

script.Parent.MouseButton1Click:Connect(function()
    game.Lighting.Ambient = Color3.new(0.66, 0, 1)
end)