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