local function l()ToggleGui(false)UIS.MouseIconEnabled=false Maid:Mark(UIS.InputBegan:Connect(function(l,Q)if l.UserInputType==Enum.UserInputType.MouseButton2 then UIS.MouseBehavior=Enum.MouseBehavior.LockCurrentPosition local Q=UIS.InputChanged:Connect(Panned)repeat l=UIS.InputEnded:wait()until l.UserInputType==Enum.UserInputType.MouseButton2 or not freeCamEnabled panDeltaMouse=Vector2.new()panDeltaGamepad=Vector2.new()Q:Disconnect()if freeCamEnabled then UIS.MouseBehavior=Enum.MouseBehavior.Default end elseif l.KeyCode==Enum.KeyCode.LeftShift or l.KeyCode==Enum.KeyCode.RightShift then SpeedModifier=.5 end end))Maid:Mark(UIS.InputEnded:Connect(function(l,Q)if l.KeyCode==Enum.KeyCode.LeftShift or l.KeyCode==Enum.KeyCode.RightShift then SpeedModifier=1 end end))camera.CameraType=Enum.CameraType.Scriptable local l,Q=GetChar()if Q then Q.Anchored=true end if l then l.WalkSpeed=0 Maid:Mark(l.Jumping:Connect(function(Q)if Q then l.Jumping=false end end))end velSpring.t,velSpring.v,velSpring.x=Vector3.new(),Vector3.new(),Vector3.new()rotSpring.t,rotSpring.v,rotSpring.x=Vector2.new(),Vector2.new(),Vector2.new()fovSpring.t,fovSpring.v,fovSpring.x=camera.FieldOfView,0,camera.FieldOfView local x=camera.CFrame local V=x.lookVector.unit stateRot=Vector2.new(math.asin(V.y),math.atan2(-V.z,V.x)-math.pi/2)panDeltaMouse=Vector2.new()local p=player:WaitForChild("\080\108\097\121\101\114\071\117\105")for l,Q in next,p:GetChildren()do if Q:IsA("\083\099\114\101\101\110\071\117\105")and Q.Enabled then Q.Enabled=false screenGuis[Q]=true end end if letterBoxEnabled then letterbox.Enabled=true end RS:BindToRenderStep("\070\114\101\101\099\097\109",Enum.RenderPriority.Camera.Value,UpdateFreecam)freeCamEnabled=true end local function Q()freeCamEnabled=false if letterBoxEnabled then letterbox.Enabled=false end UIS.MouseIconEnabled=true UIS.MouseBehavior=Enum.MouseBehavior.Default Maid:Sweep()RS:UnbindFromRenderStep("\070\114\101\101\099\097\109")local l,Q=GetChar()if l then l.WalkSpeed=16 end if Q then Q.Anchored=false end camera.FieldOfView=DEF_FOV camera.CameraType=Enum.CameraType.Custom for l in next,screenGuis do l.Enabled=true end screenGuis={}ToggleGui(true)end


local function EnterFreecam()
	ToggleGui(false)
	UIS.MouseIconEnabled = false
	Maid:Mark(UIS.InputBegan:Connect(function(input, processed)
		if input.UserInputType == Enum.UserInputType.MouseButton2 then
			UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
			local conn = UIS.InputChanged:Connect(Panned)
			repeat
				input = UIS.InputEnded:wait()
			until input.UserInputType == Enum.UserInputType.MouseButton2 or not freeCamEnabled
			panDeltaMouse = Vector2.new()
			panDeltaGamepad = Vector2.new()
			conn:Disconnect()
			if freeCamEnabled then
				UIS.MouseBehavior = Enum.MouseBehavior.Default
			end
		elseif input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
			SpeedModifier = 0.5
		end
	end))

	Maid:Mark(UIS.InputEnded:Connect(function(input, processed)
		if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
			SpeedModifier = 1
		end
	end))

	camera.CameraType = Enum.CameraType.Scriptable

	local hum, hrp = GetChar()
	if hrp then
		hrp.Anchored = true
	end
	if hum then
		hum.WalkSpeed = 0
		Maid:Mark(hum.Jumping:Connect(function(active)
			if active then
				hum.Jumping = false
			end
		end))
	end

	velSpring.t, velSpring.v, velSpring.x = Vector3.new(), Vector3.new(), Vector3.new()
	rotSpring.t, rotSpring.v, rotSpring.x = Vector2.new(), Vector2.new(), Vector2.new()
	fovSpring.t, fovSpring.v, fovSpring.x = camera.FieldOfView, 0, camera.FieldOfView

	local camCFrame = camera.CFrame
	local lookVector = camCFrame.lookVector.unit

	stateRot = Vector2.new(
		math.asin(lookVector.y),
		math.atan2(-lookVector.z, lookVector.x) - math.pi/2
	)
	panDeltaMouse = Vector2.new()

	local playerGui = player:WaitForChild("PlayerGui")
	for _, obj in next, playerGui:GetChildren() do
		if obj:IsA("ScreenGui") and obj.Enabled then
			obj.Enabled = false
			screenGuis[obj] = true
		end
	end
	if letterBoxEnabled then
		letterbox.Enabled = true
	end
	RS:BindToRenderStep("Freecam", Enum.RenderPriority.Camera.Value, UpdateFreecam)
	freeCamEnabled = true
end

local function ExitFreecam()
	freeCamEnabled = false
	if letterBoxEnabled then
		letterbox.Enabled = false
	end
	UIS.MouseIconEnabled = true
	UIS.MouseBehavior = Enum.MouseBehavior.Default
	Maid:Sweep()
	RS:UnbindFromRenderStep("Freecam")
	local hum, hrp = GetChar()
	if hum then
		hum.WalkSpeed = 16
	end
	if hrp then
		hrp.Anchored = false
	end
	camera.FieldOfView = DEF_FOV
	camera.CameraType = Enum.CameraType.Custom
	for obj in next, screenGuis do
		obj.Enabled = true
	end
	screenGuis = {}
	ToggleGui(true)
end
