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


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


