Is there a way to read the players zoom distance in a script?

I am trying to read the players zoom distance every time the player adjusts the distance, The reason I want to is so when a player zooms into 1st person I want to disable the gui’s so the player can get cinematic shots without gui in the way or just so the player doesn’t zoom in while a GUI is open and gets stuck.

I’ve tried looking in the API but only found max and minimum zoom distance as a player property

player.ZoomDistance.Changed:Connect(function()
if player.ZoomDistance => 0.5 then
--gui disable
elseif player.ZoomDistance =< 0.5 then
--re enable if disabled
end
end)

Maybe try checking the distance magnitude from the humanoid root part to the camera?

1 Like

couldnt find one either. what i did instead was get the distance between the camera and the character’s head. usually anything less than 1 means the player is zoomed into 1st person.

1 Like

Do you know how I can structure this, I don’t know where to start

local head = game.Players.LocalPlayer.Character.Head
local cam = workspace.CurrentCamera

game:GetService("RunService").RenderStepped:Connect(function()
	if (head.Position-cam.CFrame.Position).Magnitude < 1 then
		--zoomed in
	else
		--zoomed out
	end
end)
1 Like

I don’t want to seem like I am asking you guys to do all the work and I’m freeloading but thank you this helped a lot.

Its no problem! ask if you need help, thats why the devfourm exists

2 Likes
local Game = game
local Workspace = workspace
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:FindFirstChild("Head") or Character:WaitForChild("Head")
local Camera = Workspace.CurrentCamera

local function OnCameraChanged()
	local Distance = (Head.Position - Camera.CFrame.Position).Magnitude
	print(if Distance < 1 then "Zoomed in." else "Zoomed out.")
end

Camera:GetPropertyChangedSignal("CFrame"):Connect(OnCameraChanged)
2 Likes