local E={}do local e local Z local B local J local T local H local s={}local D={Backpack=true;Chat=true,Health=true;PlayerList=true}local w={BadgesNotificationsActive=true,PointsNotificationsActive=true}function E.Push()for E in pairs(D)do D[E]=StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType[E])StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[E],false)end for E in pairs(w)do w[E]=StarterGui:GetCore(E)StarterGui:SetCore(E,false)end local E=LocalPlayer:FindFirstChildOfClass("\080\108\097\121\101\114\071\117\105")if E then for E,e in pairs(E:GetChildren())do if e:IsA("\083\099\114\101\101\110\071\117\105")and e.Enabled then s[#s+1]=e e.Enabled=false end end end H=Camera.FieldOfView Camera.FieldOfView=70 B=Camera.CameraType Camera.CameraType=Enum.CameraType.Custom T=Camera.CFrame J=Camera.Focus Z=UserInputService.MouseIconEnabled UserInputService.MouseIconEnabled=false e=UserInputService.MouseBehavior UserInputService.MouseBehavior=Enum.MouseBehavior.Default end function E.Pop()for E,e in pairs(D)do StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[E],e)end for E,e in pairs(w)do StarterGui:SetCore(E,e)end for E,e in pairs(s)do if e.Parent then e.Enabled=true end end Camera.FieldOfView=H H=nil Camera.CameraType=B B=nil Camera.CFrame=T T=nil Camera.Focus=J J=nil UserInputService.MouseIconEnabled=Z Z=nil UserInputService.MouseBehavior=e e=nil end end local function e()local e=Camera.CFrame cameraRot=Vector2.new(e:toEulerAnglesYXZ())cameraPos=e.p cameraFov=Camera.FieldOfView velSpring:Reset(Vector3.new())panSpring:Reset(Vector2.new())fovSpring:Reset(0)E.Push()RunService:BindToRenderStep("\070\114\101\101\099\097\109",Enum.RenderPriority.Camera.Value+10,StepFreecam)Input.StartCapture()local Z=LocalPlayer.Character:GetChildren()for E=1,#Z,1 do local e=Z[E]if e:IsA("\066\097\115\101\080\097\114\116")or e:IsA("\077\101\115\104\080\097\114\116")then e.Transparency=1 end end end local function Z()Input.StopCapture()RunService:UnbindFromRenderStep("\070\114\101\101\099\097\109")E.Pop()local e=LocalPlayer.Character:GetChildren()for E=1,#e,1 do local Z=e[E]if(Z:IsA("\066\097\115\101\080\097\114\116")or Z:IsA("\077\101\115\104\080\097\114\116"))and Z.Name~="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"then Z.Transparency=0 end end end
------------------------------------------------------------------------

local PlayerState = {}
do
	local mouseBehavior
	local mouseIconEnabled
	local cameraType
	local cameraFocus
	local cameraCFrame
	local cameraFieldOfView
	local screenGuis = {}
	local coreGuis = {
		Backpack = true,
		Chat = true,
		Health = true,
		PlayerList = true,
	}
	local setCores = {
		BadgesNotificationsActive = true,
		PointsNotificationsActive = true,
	}

	-- 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

		cameraCFrame = Camera.CFrame
		cameraFocus = Camera.Focus

		mouseIconEnabled = UserInputService.MouseIconEnabled
		UserInputService.MouseIconEnabled = false

		mouseBehavior = UserInputService.MouseBehavior
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default
	end

	-- Restore state
	function PlayerState.Pop()
		for name, isEnabled in pairs(coreGuis) do
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], isEnabled)
		end
		for name, isEnabled in pairs(setCores) do
			StarterGui:SetCore(name, isEnabled)
		end
		for _, gui in pairs(screenGuis) do
			if gui.Parent then
				gui.Enabled = true
			end
		end

		Camera.FieldOfView = cameraFieldOfView
		cameraFieldOfView = nil

		Camera.CameraType = cameraType
		cameraType = nil

		Camera.CFrame = cameraCFrame
		cameraCFrame = nil

		Camera.Focus = cameraFocus
		cameraFocus = nil

		UserInputService.MouseIconEnabled = mouseIconEnabled
		mouseIconEnabled = nil

		UserInputService.MouseBehavior = mouseBehavior
		mouseBehavior = nil
	end
end

local function StartFreecam()
	local cameraCFrame = Camera.CFrame
	cameraRot = Vector2.new(cameraCFrame:toEulerAnglesYXZ())
	cameraPos = cameraCFrame.p
	cameraFov = Camera.FieldOfView

	velSpring:Reset(Vector3.new())
	panSpring:Reset(Vector2.new())
	fovSpring:Reset(0)

	PlayerState.Push()
	RunService:BindToRenderStep("Freecam", Enum.RenderPriority.Camera.Value + 10, StepFreecam)
	Input.StartCapture()

	local charParts = LocalPlayer.Character:GetChildren()
	for i = 1, #charParts do
		local part = charParts[i]
		if part:IsA("BasePart") or part:IsA("MeshPart") then
			part.Transparency = 1
		end
	end
end

local function StopFreecam()
	Input.StopCapture()
	RunService:UnbindFromRenderStep("Freecam")
	PlayerState.Pop()

	local charParts = LocalPlayer.Character:GetChildren()
	for i = 1, #charParts do
		local part = charParts[i]
		if (part:IsA("BasePart") or part:IsA("MeshPart")) and part.Name ~= "HumanoidRootPart" then
			part.Transparency = 0
		end
	end
end
