Help with Camera Zooming Script

Hello Fellow Developers!,
I have recently ran into an issue which i cant seem to find the solution to anywhere,
i will keep it short and simple,

i have a script in starter player scripts, which makes you zoom in/out when a key is pressed, the code works, only problem is that when the character first loads in, the script dosent seem to work, but after resetting the character it works always after that, and unfortuantly resetting that character isnt an option in the game im trying to create, if there is some way i could load the script without the character needing to be reset, please comment below. Any support is appricated

here is the code for the client script in starterplayerscripts

-- Client Script
local Player = game.Players.LocalPlayer
local FPVAL = script.InFP
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input,GameProcessed)
	if not GameProcessed then
		if input.KeyCode == Enum.KeyCode.V then
			wait()
			FPVAL.Value = not FPVAL.Value
			if FPVAL.Value == true then
			Player.CameraMaxZoomDistance = 0.5
			Player.CameraMinZoomDistance = 0.5
			elseif FPVAL.Value == false then
			Player.CameraMaxZoomDistance = 14
			Player.CameraMinZoomDistance = 14
			end
			wait()
			
		end
	end
end)

*note FPVAL is a Boolean value i have attached to the script to know if the player is in first pearson or not.
I made sure that the input wasn’t game processed so player wasn’t typing in chat and changing their FOV

Again any help is appricated and i am open to criticism.

see if this works m8

local GS = game.GetService

local P = GS(game,"Players")
local UIS = GS(game,"UserInputService")

local LP = P.LocalPlayer

local bool = false

UIS.InputBegan:Connect(function(yuh,yeet)
	if not yeet and yuh.KeyCode == Enum.KeyCode.V then
		bool = not bool
		if bool then
			LP.CameraMinZoomDistance = 0
			LP.CameraMaxZoomDistance = 0
		elseif not bool then
			LP.CameraMaxZoomDistance = 14
			LP.CameraMinZoomDistance = 14
		end
	end
end)
1 Like

ill try it now, thanks for the help!

thanks, that worked perfectly, and i have realised my mistake, thanks for the support!

I really didn’t change anything at all, I just changed the lines of these 2 bits of code. I guess it’s just how Roblox’s ordering works for whatever reason. Glad to be of help.
image

1 Like