Issues Third-Person toggleView Adjustment

Hello! I need some help with my third-person toggleView.

The issue is as follows: when I switch to third-person view, the perspective is not displayed correctly, and the player lacks a head and doesn’t move as expected. How can I adjust it correctly when switching to third-person view?

video showing issue:

module script:

-- CameraModuleScript

local CameraModule = {}

function CameraModule.setupCamera(character, camera, forwardOffset, upwardOffset)
	local head = character:WaitForChild("Head")

	local function updateCameraPosition()
		local offset = Vector3.new(0, upwardOffset, forwardOffset)
		camera.CFrame = CFrame.new(head.Position + offset)
	end

	-- Set the initial camera position
	updateCameraPosition()

	-- Continuously update the camera position to follow the head
	head:GetPropertyChangedSignal("Position"):Connect(updateCameraPosition)

	local isThirdPerson = false

	local function toggleCameraView()
		print("toggleCameraView called")
		isThirdPerson = not isThirdPerson
		if isThirdPerson then
			-- Change to third-person view
			print("Changed to third-person view")
			camera.CameraType = Enum.CameraType.Scriptable
		else
			-- Change back to first-person view
			print("Changed to first-person view")
			camera.CameraType = Enum.CameraType.Custom
		end
	end

	local function setupInput()
		local UIS = game:GetService("UserInputService")

		UIS.InputBegan:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.E then
				toggleCameraView()
			end
		end)
	end

	setupInput()
end

return CameraModule

localscript:

-- LocalScript

local CameraModule = require(game.ReplicatedStorage:WaitForChild("CameraSwitchModule"))

local player = game.Players.LocalPlayer

local function onCharacterAdded(character)
	local camera = game.Workspace.CurrentCamera

	-- Adjust these variables for customization
	local forwardOffset = 3
	local upwardOffset = 1.5

	-- Use the function from the module to set up the camera
	CameraModule.setupCamera(character, camera, forwardOffset, upwardOffset)
end

-- Check if the character is already there
local character = player.Character
if character then
	onCharacterAdded(character)
end

-- Listen for character added
player.CharacterAdded:Connect(onCharacterAdded)

project organization:
image

I have made a replicative first-person perspective script before, and I think I might know the solution.

But first, I want to inform you that you should use LocalTransparencyModifier for your head’s transparency instead of the normal one. This property is usually hidden, but accessible.

When enabling the third-person view, set the camera mode to Enum.CameraMode.LockThirdPerson, and the opposite for Enum.CameraMode.LockFirstPerson.

Something like this? i got an error :frowning:

local function toggleCameraView()
		print("toggleCameraView called")
		isThirdPerson = not isThirdPerson
		if isThirdPerson then
			-- Change to third-person view
			print("Changed to third-person view")
			camera.CameraType = Enum.CameraType.Scriptable
			camera.CameraMode = Enum.CameraMode.Classic

			-- Set LocalTransparencyModifier for head transparency
			local head = character:WaitForChild("Head")
			if head then
				head.LocalTransparencyModifier = 0.5 -- You can adjust the transparency value
			end
		else
			-- Change back to first-person view
			print("Changed to first-person view")
			camera.CameraType = Enum.CameraType.Custom
			camera.CameraMode = Enum.CameraMode.LockFirstPerson

			-- Reset LocalTransparencyModifier for head transparency
			local head = character:FindFirstChild("Head")
			if head then
				head.LocalTransparencyModifier = 0
			end
		end
	end