Make mouse stay in the middle (in first person) when setting Camera CFrame to another part?

Hello everyone, I’ve been trying to make my mouse stay in the middle (in first person) while setting camera’s cframe to a part. When I set the camera cframe to a part, the mouse becomes “free” and the camera won’t move with it. The camera is set to the player’s head, which means the camera should move with the head. Problem is the mouse will be able to move around freely which causes the camera to be stuck.

local crouching = char.Crouching
local cdforcrouch = false
function crouch(trueorfalse)
	if cdforcrouch == true then 
		return
	end
	if trueorfalse == true then
		cdforcrouch = true -- Enable crouch!
		crouching.Value = true
		script.Parent.CameraRotate.Disabled = true
		char.Animate.Disabled = true
		char.CrouchAnimation.Disabled = false
		humanoid.WalkSpeed = 9
		humanoid.JumpPower = 0
		Camera.CameraType = Enum.CameraType.Scriptable
		coroutine.resume(coroutine.create(function()
			while true do
				wait(0.1)
				if crouching.Value == false then break end
				Camera.CFrame = char.Head.CFrame -- This part sets the camera to the head's cframe every 0.1 seconds, so it moves with it.
			end
		end))
		wait(0.1)
		cdforcrouch = false
	else
		cdforcrouch = true -- Disable Crouch!
		script.Parent.CameraRotate.Disabled = false
		crouching.Value = false
		char.Animate.Disabled = false
		char.CrouchAnimation.Disabled = true
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 30
		Camera.CameraType = Enum.CameraType.Custom
		wait(0.1)
		cdforcrouch = false
	end
end

Use MouseBehavior.

local UIS = game:GetService("UserInputService")
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter