How to check if player's camera is below a specific position Y?

Hello!
The title says it all already, I want to make a underwater camera system so, when the player’s camera is below position y0, the lighting effects apply. I’ve got a script already, however it works with HumanoidRootPart and it’s not so precise.

local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local character = player.Character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")


RunService.RenderStepped:Connect(function()
	if HumanoidRootPart.Position.Y >= 0 then
		game.Lighting.UnderwaterCC.Enabled = false
		game.Lighting.UnderWaterBlur.Enabled = false
		game.Lighting.UnderwaterAtmosphere.Density = 0
		game.Lighting.Atmosphere.Density = 0.188
		game.Lighting.Ambient = Color3.fromRGB(117,117,117)
		if game.SoundService.Underwater.IsPlaying == true then
			game.SoundService.Underwater:Stop()
		elseif game.SoundService.Underwater.IsPlaying == false then
			game.SoundService.Underwater:Stop()
		end
	elseif HumanoidRootPart.Position.Y < 0 then
		game.Lighting.UnderwaterCC.Enabled = true
		game.Lighting.UnderWaterBlur.Enabled = true
		game.Lighting.UnderwaterAtmosphere.Density = 0.375
		game.Lighting.Atmosphere.Density = 0
		game.Lighting.Ambient = Color3.fromRGB(255, 255, 255)
		if game.SoundService.Underwater.IsPlaying == true then
			game.SoundService.Underwater:Play()
		elseif game.SoundService.Underwater.IsPlaying == false then
			game.SoundService.Underwater:Play()
		end
	end
end)
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera

do
   local db = false
   RunService.RenderStepped:Connect(function()
		if camera.CFrame.Position.Y >= 0 and not db then
			db = not db
			game.Lighting.UnderwaterCC.Enabled = false
			game.Lighting.UnderWaterBlur.Enabled = false
			game.Lighting.UnderwaterAtmosphere.Density = 0
			game.Lighting.Atmosphere.Density = 0.188
			game.Lighting.Ambient = Color3.fromRGB(117,117,117)
			if game.SoundService.Underwater.IsPlaying == true then
				game.SoundService.Underwater:Stop()
			elseif game.SoundService.Underwater.IsPlaying == false then
				game.SoundService.Underwater:Stop()
			end
		elseif camera.CFrame.Position.Y < 0 and db then
			db = not db
			game.Lighting.UnderwaterCC.Enabled = true
			game.Lighting.UnderWaterBlur.Enabled = true
			game.Lighting.UnderwaterAtmosphere.Density = 0.375
			game.Lighting.Atmosphere.Density = 0
			game.Lighting.Ambient = Color3.fromRGB(255, 255, 255)
			if game.SoundService.Underwater.IsPlaying == true then
				game.SoundService.Underwater:Play()
			elseif game.SoundService.Underwater.IsPlaying == false then
				game.SoundService.Underwater:Play()
			end
		end
	end)
end

The debounce (db) is so you dont unnecessary update the lighting for no reason, in theory this should lead to less lag for the player.
I put it in a do end so db is a local variable, db is not really a debounce its more an is activated boolean.
To get the Camera’s position you can use camera.CFrame.Position
The player’s camera is workspace.CurrentCamera (only client-sided)

If this helped you please close the topic! :smiley: