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)
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.
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)
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)