Camera Change not working

Hi, so I want the camera locked in first person, but when the player presses “C” it unlocks the camera and are forced out of first person and can move the mouse freely. It’s not working. The script gives no errors and goes through the entire code but it doesn’t even do anything. Here is my current code:

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local count = 0

print("set variables")

UIS.InputBegan:Connect(function(input)
	print("made func")
	if input.KeyCode == Enum.KeyCode.C and count == 0 then
		plr.CameraMinZoomDistance = 3
		count = 1
	elseif count == 1 and input.KeyCode == Enum.KeyCode.C then
		plr.CameraMinZoomDistance = 0.5
		count = 0
	end
	print("did everything")
end)

Can anyone help?

try this code out

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local count = 0

print("set variables")

UIS.InputBegan:Connect(function(input)
	print("made func")
	if input.KeyCode == Enum.KeyCode.C and count == 0 then
		plr.CameraMaxZoomDistance = 3
		count = 1
	elseif count == 1 and input.KeyCode == Enum.KeyCode.C then
		plr.CameraMaxZoomDistance = 0.5
		count = 0
	end
	print("did everything")
end)

Works except I want it to force the player out of first person

Well if count is only 1 or 0 you might as well use a bool value for count

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local count = false
--print("set variables")

UIS.InputBegan:Connect(function(input,gp)
	--print("made func")
	if input.KeyCode == Enum.KeyCode.C and not count and not gp then -- First-person on
		plr.CameraMinZoomDistance = 3
plr.CameraMode = Enum.CameraMode.LockFirstPerson
		count = true
	elseif input.KeyCode == Enum.KeyCode.C and count and not gp then -- First-person off
plr.CameraMode = Enum.CameraMode.Classic
		plr.CameraMinZoomDistance = 0.5
		count = false
	end
	--print("did everything")
end)

try this then

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local count = 0

print("set variables")

UIS.InputBegan:Connect(function(input)
	print("made func")
	if input.KeyCode == Enum.KeyCode.C and count == 0 then
		plr.CameraMaxZoomDistance = 3
		count = 1
	elseif count == 1 and input.KeyCode == Enum.KeyCode.C then
		plr.CameraMode = Enum.CameraMode.LockFirstPerson
		count = 0
	end
	print("did everything")
end)

Works except when I press C I want the camera to FORCE the player in third person. I don’t want the player to scroll out I just want it to force it out.

Oh gime a min, ill look into that

try this one

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local count = 0

print("set variables")

UIS.InputBegan:Connect(function(input)
	print("made func")
	if input.KeyCode == Enum.KeyCode.C and count == 0 then
		plr.CameraMaxZoomDistance = 3
        plr.CameraMinZoomDistance = 3
		count = 1
	elseif count == 1 and input.KeyCode == Enum.KeyCode.C then
		plr.CameraMode = Enum.CameraMode.LockFirstPerson
		count = 0
	end
	print("did everything")
end)

TYSM Except I can only do it one time. I’m pretty sure that is a really easy fix though.

2 Likes

@kittyPGR

Made some changes to your code to suit my problem. Thank you for helping!!

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local count = 0

print("set variables")

UIS.InputBegan:Connect(function(input)
	print("made func")
	if input.KeyCode == Enum.KeyCode.C and count == 0 then
		plr.CameraMode = Enum.CameraMode.Classic
		plr.CameraMaxZoomDistance = 5
		plr.CameraMinZoomDistance = 5
		count = 1
	elseif count == 1 and input.KeyCode == Enum.KeyCode.C then
		plr.CameraMode = Enum.CameraMode.LockFirstPerson
		count = 0
	end
	print("did everything")
end)