Freecam should Save mouseBehavior before setting CameraType to Custom

I had a custom Force Shiftlock CameraScript and the mouse position stayed locked after leaving Freecam and returning to Scriptable. This is because the Camera.CameraType was set to Enum.CameraType.Custom in the Freecam before they saved the mouseBehavior.

My custom CameraScript makes it so Mouse has Enum.MouseBehavior.LockCenter if it is Enum.CameraType.Custom and Mouse has Enum.MouseBehavior.Default if it is Enum.CameraType.Scriptable.

So this is what it looks like:

-- Save state and set up for freecam
function PlayerState.Push()
	for name in pairs(coreGuis) do
		coreGuis[name] = StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType[name])
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], false)
	end
	for name in pairs(setCores) do
		setCores[name] = StarterGui:GetCore(name)
		StarterGui:SetCore(name, false)
	end
	local playergui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
	if playergui then
		for _, gui in pairs(playergui:GetChildren()) do
			if gui:IsA("ScreenGui") and gui.Enabled then
				screenGuis[#screenGuis + 1] = gui
				gui.Enabled = false
			end
		end
	end

	cameraFieldOfView = Camera.FieldOfView
	Camera.FieldOfView = 70

	cameraType = Camera.CameraType
	Camera.CameraType = Enum.CameraType.Custom -- Here

	cameraCFrame = Camera.CFrame
	cameraFocus = Camera.Focus

	mouseIconEnabled = UserInputService.MouseIconEnabled
	UserInputService.MouseIconEnabled = false

	if FFlagUserExitFreecamBreaksWithShiftlock and CheckMouseLockAvailability() then
		mouseBehavior = Enum.MouseBehavior.Default
	else
		mouseBehavior = UserInputService.MouseBehavior
	end
	UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end

This is what they should’ve done:

-- Save state and set up for freecam
function PlayerState.Push()
	for name in pairs(coreGuis) do
		coreGuis[name] = StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType[name])
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], false)
	end
	for name in pairs(setCores) do
		setCores[name] = StarterGui:GetCore(name)
		StarterGui:SetCore(name, false)
	end
	local playergui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
	if playergui then
		for _, gui in pairs(playergui:GetChildren()) do
			if gui:IsA("ScreenGui") and gui.Enabled then
				screenGuis[#screenGuis + 1] = gui
				gui.Enabled = false
			end
		end
	end

	cameraFieldOfView = Camera.FieldOfView
	Camera.FieldOfView = 70

	cameraType = Camera.CameraType

	cameraCFrame = Camera.CFrame
	cameraFocus = Camera.Focus

	mouseIconEnabled = UserInputService.MouseIconEnabled
	UserInputService.MouseIconEnabled = false

	if FFlagUserExitFreecamBreaksWithShiftlock and CheckMouseLockAvailability() then
		mouseBehavior = Enum.MouseBehavior.Default
	else
		mouseBehavior = UserInputService.MouseBehavior
	end
	UserInputService.MouseBehavior = Enum.MouseBehavior.Default

	Camera.CameraType = Enum.CameraType.Custom -- Here
end

This is not a big deal though since there aren’t much people with custom CameraScripts, but they should do this to help those people who want Freecam with their custom CameraScript.

1 Like