local function q()ToggleGui(false)Maid:Mark(UIS.InputBegan:Connect(function(q,r)if q.UserInputType==Enum.UserInputType.MouseButton2 then UIS.MouseBehavior=Enum.MouseBehavior.LockCurrentPosition local r=UIS.InputChanged:Connect(Panned)repeat q=UIS.InputEnded:wait()until q.UserInputType==Enum.UserInputType.MouseButton2 or not freeCamEnabled panDeltaMouse=Vector2.new()panDeltaGamepad=Vector2.new()r:Disconnect()if freeCamEnabled then UIS.MouseBehavior=Enum.MouseBehavior.Default end elseif q.KeyCode==Enum.KeyCode.LeftShift or q.KeyCode==Enum.KeyCode.RightShift then SpeedModifier=.5 end end))Maid:Mark(UIS.InputEnded:Connect(function(q,r)if q.KeyCode==Enum.KeyCode.LeftShift or q.KeyCode==Enum.KeyCode.RightShift then SpeedModifier=1 end end))camera.CameraType=Enum.CameraType.Scriptable local q,r=GetChar()if r then r.Anchored=true end if q then q.WalkSpeed=0 Maid:Mark(q.Jumping:Connect(function(r)if r then q.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 w=camera.CFrame local B=w.lookVector.unit stateRot=Vector2.new(math.asin(B.y),math.atan2(-B.z,B.x)-math.pi/2)panDeltaMouse=Vector2.new()local E=player:WaitForChild("\080\108\097\121\101\114\071\117\105")for q,r in next,E:GetChildren()do if r:IsA("\083\099\114\101\101\110\071\117\105")and r.Enabled then r.Enabled=false screenGuis[r]=true end end if LETTERBOX then letterbox.Enabled=true end RS:BindToRenderStep("\070\114\101\101\099\097\109",Enum.RenderPriority.Camera.Value,UpdateFreecam)freeCamEnabled=true end local function r()freeCamEnabled=false if LETTERBOX then letterbox.Enabled=false end UIS.MouseBehavior=Enum.MouseBehavior.Default Maid:Sweep()RS:UnbindFromRenderStep("\070\114\101\101\099\097\109")local q,r=GetChar()if q then q.WalkSpeed=16 end if r then r.Anchored=false end camera.FieldOfView=DEF_FOV camera.CameraType=Enum.CameraType.Custom for q in next,screenGuis do q.Enabled=true end screenGuis={}ToggleGui(true)end script.Parent.RightFrame.Button.Activated:Connect(function()task.wait(.05)if Debounce then script.Parent.RightFrame.Button.Point:TweenPosition(UDim2.new(.07,0,.108,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,.15);(TweenService:Create(script.Parent.RightFrame.Button,TweenInfo.new(.35,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{BackgroundColor3=Color3.fromRGB(95,95,95)})):Play()r()Debounce=not Debounce else script.Parent.RightFrame.Button.Point:TweenPosition(UDim2.new(.57,0,.108,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,.15);(TweenService:Create(script.Parent.RightFrame.Button,TweenInfo.new(.35,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{BackgroundColor3=Color3.fromRGB(255,85,0)})):Play()q()Players.LocalPlayer.PlayerGui.ContentCreator.Enabled=true Debounce=not Debounce end 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 LETTERBOX then
		letterbox.Enabled = true
	end
	RS:BindToRenderStep("Freecam", Enum.RenderPriority.Camera.Value, UpdateFreecam)
	freeCamEnabled = true
end

local function ExitFreecam()
	freeCamEnabled = false
	if LETTERBOX 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

script.Parent.RightFrame.Button.Activated:Connect(function()
	task.wait(0.05)
	if Debounce then
		script.Parent.RightFrame.Button.Point:TweenPosition(
			UDim2.new(0.07, 0, 0.108, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Linear,
			0.15
		)
		TweenService:Create(
			script.Parent.RightFrame.Button,
			TweenInfo.new(0.35, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
			{
				BackgroundColor3 = Color3.fromRGB(95, 95, 95),
			}
		):Play()
		ExitFreecam()
		Debounce = not Debounce
	else
		script.Parent.RightFrame.Button.Point:TweenPosition(
			UDim2.new(0.57, 0, 0.108, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Linear,
			0.15
		)
		TweenService:Create(
			script.Parent.RightFrame.Button,
			TweenInfo.new(0.35, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
			{
				BackgroundColor3 = Color3.fromRGB(255, 85, 0),
			}
		):Play()
		EnterFreecam()
		Players.LocalPlayer.PlayerGui.ContentCreator.Enabled = true
		Debounce = not Debounce
	end
end)
