If statement is not running correctly

Hello, below is the code to what I hoped would be a simple dynamic depth of field effect for my game, using rays. The script is placed in StarterCharacterScripts.

local RunService = game:GetService("RunService")
local lighting = game:GetService("Lighting")
local depthOfField = game.Lighting.DepthOfField
local camera = workspace.CurrentCamera

function increaseIntesity()
	for count = .3,1,.1 do
		depthOfField.FarIntensity = count
		wait()
	end
end

function decreaseIntesity()
	for count = 1,.3,-0.1 do
		depthOfField.FarIntensity = count
		wait()
	end
end

function increaseFocusDistance()
	for count = 30,100,2 do
		depthOfField.FocusDistance = count
		wait()
	end
end

function decreaseFocusDistance()
	for count = 100,30,-2 do
		depthOfField.FocusDistance = count
		wait()
	end
end

local rayLength = 100
local viewportPoint = camera.ViewportSize / 2

local changeNumber = 40

RunService.RenderStepped:Connect(function()
	local unitRay = camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
	local ray = Ray.new(unitRay.Origin, unitRay.Direction * rayLength)
	
	local hit, position = workspace:FindPartOnRay(ray)
	
	if (camera.CFrame.Position - position).magnitude < changeNumber then
            print("first if statement running")
	    if depthOfField.FarIntensity == 0.3 and depthOfField.FocusDistance == 100 then  -- not working
			print("second if statement running")
			increaseIntesity()
			decreaseFocusDistance()
		end
	elseif (camera.CFrame.Position - position).magnitude > changeNumber or hit == nil then
		if depthOfField.FarIntensity == 1 and depthOfField.FocusDistance == 30 then -- not working
			increaseFocusDistance()
			decreaseIntesity()
		end
	end
end)

The ray is working perfectly, however my issue is with the two if statements that I have labeled above, the DepthOfField values are set correctly in studio, and there are no error messages. This might be because i am using the if statement wrong or something to do with DepthOfField itself. I would appreciate some help, thanks.

Well try printing the depthofField values and values that you’re checking before the if statements. Just to make sure they should be working.

i added print(depthOfField.FarIntensity, depthOfField.FocusDistance) in front of both if statements.

it prints “1 30” which are the set vales of depthoffield

FarIntensity is only a whole number if its 0 or 1, it does have a small decimal at the end for numbers in the range between. What I did was swapped out == for >=. That way the if statement accounted for the extra decimal places.

 if depthOfField.FarIntensity >= 0.3 and depthOfField.FocusDistance >= 100 then

Just apply this to the rest of your if statements and change if needed.

Thank you, that was the problem.