local Q=false local i=false Freecam=function()UserInputService.MouseIconEnabled=not UserInputService.MouseIconEnabled if not Q then Q=not Q Camera.CameraType="\083\099\114\105\112\116\097\098\108\101"i=true while i do task.wait()local Q=Mouse.Hit.Position local i=CFrame.new(Camera.CFrame.Position,Q)local N=UserInputService:GetMouseButtonsPressed()if#N~=0 then if N[1].UserInputType==Enum.UserInputType.MouseButton1 then i*=CFrame.new(0,0,-5)elseif N[1].UserInputType==Enum.UserInputType.MouseButton2 then i*=CFrame.new(0,0,5)end end;(TweenService:Create(Camera,TweenInfo.new(.25),{CFrame=i})):Play()end else Q=not Q i=false Player.Character.HumanoidRootPart.CFrame=Camera.CFrame Camera.CameraType="\067\117\115\116\111\109"end end ShiftLockToggle=function()Locked=not Locked local Q=Player.Character.HumanoidRootPart local i=0 while Locked do task.wait()local i=Camera.CFrame.LookVector i=(Vector3.new(i.x,0,i.z)).Unit local N=math.atan2(-i.x,-i.z)Q.CFrame=CFrame.new(Q.Position)*CFrame.Angles(0,N,0)end end Run=function(Q,i)Q.WalkSpeed=23.5 local N=Q:LoadAnimation(script.Run)N:Play()if not isMobile then repeat task.wait()until not UserInputService:IsKeyDown(i)else UserInputService.InputEnded:Wait()end Q.WalkSpeed=16 N:Stop()N:Remove()end Input=function(Q,i)if i then return end repeat task.wait()until Player.Character local N=Player.Character local B=N:WaitForChild("\072\117\109\097\110\111\105\100")local V=Q.KeyCode if table.find(DirectionalKeys,V)then if tick()-LastDirectional<.2 and LastKeyDown==V then Run(B,V)end LastDirectional=tick()end LastKeyDown=V end
--- FUNCTIONS ---

local isFreecam = false
local MouseListening = false
Freecam = function()
	UserInputService.MouseIconEnabled = not UserInputService.MouseIconEnabled

	if not isFreecam then
		isFreecam = not isFreecam

		Camera.CameraType = "Scriptable"
		-- When mouse button 1 is held down go move camera forward in direction its facing, go backwards with mouse button 2
		MouseListening = true
		while MouseListening do
			task.wait()

			local MouseInstancePos = Mouse.Hit.Position
			-- Look at MouseInstancePos
			local Final = CFrame.new(Camera.CFrame.Position, MouseInstancePos)

			local DownButtons = UserInputService:GetMouseButtonsPressed()
			if #DownButtons ~= 0 then
				if DownButtons[1].UserInputType == Enum.UserInputType.MouseButton1 then
					Final *= CFrame.new(0, 0, -5)
				elseif DownButtons[1].UserInputType == Enum.UserInputType.MouseButton2 then
					Final *= CFrame.new(0, 0, 5)
				end
			end

			TweenService:Create(Camera, TweenInfo.new(0.25), { CFrame = Final }):Play()
		end
	else
		isFreecam = not isFreecam
		MouseListening = false
		Player.Character.HumanoidRootPart.CFrame = Camera.CFrame
		Camera.CameraType = "Custom"
	end
end

ShiftLockToggle = function()
	Locked = not Locked

	-- Fix HRP to the camera direction
	local HumanoidRootPart = Player.Character.HumanoidRootPart
	local previousAngle = 0
	while Locked do
		task.wait()
		local cameraForward = Camera.CFrame.LookVector
		cameraForward = Vector3.new(cameraForward.x, 0, cameraForward.z).Unit

		local angle = math.atan2(-cameraForward.x, -cameraForward.z)
		HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, angle, 0)
	end
end

Run = function(Humanoid, KeyCode)
	Humanoid.WalkSpeed = 23.5

	local RunAnimation = Humanoid:LoadAnimation(script.Run)
	RunAnimation:Play()

	if not isMobile then
		repeat
			task.wait()
		until not UserInputService:IsKeyDown(KeyCode)
	else
		UserInputService.InputEnded:Wait()
	end
	Humanoid.WalkSpeed = 16

	RunAnimation:Stop()
	RunAnimation:Remove()
end

Input = function(Input, Typing)
	if Typing then
		return
	end

	repeat
		task.wait()
	until Player.Character
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")

	local KeyCode = Input.KeyCode

	if table.find(DirectionalKeys, KeyCode) then
		if (tick() - LastDirectional < 0.2) and LastKeyDown == KeyCode then
			Run(Humanoid, KeyCode)
		end

		LastDirectional = tick()
	end

	LastKeyDown = KeyCode
end
