Bug in screen darkening effect when looking at the sun

hello scripters! I have this script here to darken the screen when you look at the sun for my mars game. When i tested the script the first time. It worked. But, when i added the intValue for the max brightness. It got locked into the minbrightness and it wont go back to the max brightness

local lighting = game:GetService("Lighting")
local currentCamera = workspace.CurrentCamera

local maxAngle = 30
local maxBrightness = game.ReplicatedStorage.Values.maxBrightness
local minBrightness = -.6

runService.RenderStepped:Connect(function()
	if (currentCamera.CFrame.LookVector - lighting:GetSunDirection()).Magnitude < maxAngle then
		if lighting.ColorCorrection.Brightness > minBrightness then
			lighting.ColorCorrection.Brightness = minBrightness/(maxAngle*(currentCamera.CFrame.LookVector - lighting:GetSunDirection()).Magnitude)
			if lighting.ColorCorrection.Brightness < minBrightness then
				lighting.ColorCorrection.Brightness = minBrightness
			end
		else
			lighting.ColorCorrection.Brightness = minBrightness
		end
	else
		lighting.ColorCorrection.Brightness = maxBrightness.Value
	end
end)

Any ideas on how to fix this? (Im also actively trying to find another post that has this issue)

1 Like

randomly fixed it somehow… So no need for answer

Final Script:

local runService = game:GetService("RunService")
local lighting = game:GetService("Lighting")
local currentCamera = workspace.CurrentCamera

local maxAngle = 30
local maxBrightness = game.ReplicatedStorage.Values.maxBrightness
local minBrightness = -.7

runService.RenderStepped:Connect(function()
	if (currentCamera.CFrame.LookVector - lighting:GetSunDirection()).Magnitude < maxAngle then
		if lighting.ColorCorrection.Brightness > minBrightness then
			lighting.ColorCorrection.Brightness = minBrightness/(maxAngle*(currentCamera.CFrame.LookVector - lighting:GetSunDirection()).Magnitude)
			if lighting.ColorCorrection.Brightness < minBrightness then
				lighting.ColorCorrection.Brightness = minBrightness
			end
		else
			lighting.ColorCorrection.Brightness = minBrightness
		end
	else
		lighting.ColorCorrection.Brightness = maxBrightness.Value
	end
	
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.