I made a script where the CameraSubject is set to a part that follows the player's torso using BodyGyro. This is to add a sway/follow effect when you move. However, you're able to look through any parts when the CameraSubject is changed, and I don't want that to happen. How can I change this?

Here is the script that I made.

local torso = script.Parent.Parent.HumanoidRootPart
local head = script.Parent.Parent.Head
local center = Instance.new("Part")
	center.Name = script.Parent.Parent.Name .. "Center"
	center.Transparency = 1
	center.CanCollide = false
	center.Size = Vector3.new(1,1,1)
	center.Position = torso.Position
	center.Parent = game.Workspace
	center.CFrame = torso.CFrame
local bp = Instance.new("BodyPosition")
	bp.position = center.Position
	bp.maxForce = Vector3.new(9e+100, 9e+100, 9e+100)
	bp.P = 40000
	bp.Parent = center
local bg = Instance.new("BodyGyro")
	bg.maxTorque = Vector3.new(9e+100, 9e+100, 9e+100)
	bg.cframe = center.CFrame
	bg.Parent = center
local cam = game.Workspace.CurrentCamera
	cam.CameraSubject = center
	cam.CameraType = Enum.CameraType.Custom
	
while torso.Parent do
	center.BodyPosition.position = torso.Position
	wait()
end

center:Remove()