local K=chr:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")local D=chr:WaitForChild("\084\111\114\115\111")local O=chr:WaitForChild("\072\101\097\100")local r=K:WaitForChild("\082\111\111\116\074\111\105\110\116")local l,V=D:WaitForChild("\082\105\103\104\116 \072\105\112"),D:WaitForChild("\076\101\102\116 \072\105\112")local M,y=D:WaitForChild("\082\105\103\104\116 \083\104\111\117\108\100\101\114"),D:WaitForChild("\076\101\102\116 \083\104\111\117\108\100\101\114")local g=D:WaitForChild("\078\101\099\107")r,g,M,y,l,V=r:Clone(),g:Clone(),M:Clone(),y:Clone(),l:Clone(),V:Clone()r.Parent,g.Parent,M.Parent,y.Parent,l.Parent,V.Parent=K,D,D,D,D,D local e,A,b,k,C,U=r.C0,g.C0,M.C0,y.C0,l.C0,V.C0 local p=script.Parent:WaitForChild("\116\114\097\110\115\102\101\114")local o=false local n=false local E E=runService.Heartbeat:Connect(function()local K=mse.Hit local D=(O.Position-cam.CFrame.p).Magnitude local s=O.CFrame.Y-cam.CFrame.Y local x=o and-math.rad(18)or 0 g.C0=g.C0:Lerp(A*CFrame.Angles(-math.atan(s/D),x,0),.2)M.C0=M.C0:Lerp(b*CFrame.Angles(0,0,math.atan(s/D)*.9),.2)y.C0=y.C0:Lerp(k*CFrame.Angles(0,0,-math.atan(s/D)*.9),.2)if n then humanoid.CameraOffset=humanoid.CameraOffset:Lerp(Vector3.new(0,-2,0),.2)r.C0=r.C0:Lerp((e*CFrame.new(0,0,-1.7))*CFrame.Angles(math.rad(20),0,0),.2)l.C0=l.C0:Lerp((C*CFrame.Angles(0,0,-math.rad(30)))*CFrame.new(.25,1.7,0),.2)V.C0=V.C0:Lerp((U*CFrame.Angles(0,0,math.rad(30)))*CFrame.new(-0.25,1.7,0),.2)else humanoid.CameraOffset=humanoid.CameraOffset:Lerp(Vector3.new(),.25)r.C0=r.C0:Lerp(e,.25)l.C0=l.C0:Lerp(C,.25)V.C0=V.C0:Lerp(U,.25)end p:FireServer(r.C0,g.C0,M.C0,y.C0,l.C0,V.C0)if humanoid:GetState()==Enum.HumanoidStateType.Dead then E:Disconnect()return end end)UIS.InputBegan:Connect(function(K,D)if not D then if K.KeyCode==Enum.KeyCode.LeftControl and(humanoid.Sit==false and humanoid.PlatformStand==false)then n=true humanoid.WalkSpeed=10 end end end)UIS.InputEnded:Connect(function(K,D)if not D then if K.KeyCode==Enum.KeyCode.LeftControl then n=false humanoid.WalkSpeed=16 end end end)script.aimEvent.Event:Connect(function(K)if type(K)=="\098\111\111\108\101\097\110"then o=K end end);(humanoid:GetPropertyChangedSignal("\083\105\116")):Connect(function()if humanoid.Sit==true then n=false humanoid.WalkSpeed=16 end end)
--humanoid.AutoRotate = false

local root = chr:WaitForChild("HumanoidRootPart")
local torso = chr:WaitForChild("Torso")
local head = chr:WaitForChild("Head")

local rj = root:WaitForChild("RootJoint")
local rh, lh = torso:WaitForChild("Right Hip"), torso:WaitForChild("Left Hip")
local rs, ls = torso:WaitForChild("Right Shoulder"), torso:WaitForChild("Left Shoulder")
local nk = torso:WaitForChild("Neck")

rj, nk, rs, ls, rh, lh = rj:Clone(), nk:Clone(), rs:Clone(), ls:Clone(), rh:Clone(), lh:Clone()
rj.Parent, nk.Parent, rs.Parent, ls.Parent, rh.Parent, lh.Parent = root, torso, torso, torso, torso, torso

local rjc0, nkc0, rsc0, lsc0, rhc0, lhc0 = rj.C0, nk.C0, rs.C0, ls.C0, rh.C0, lh.C0

local transfer = script.Parent:WaitForChild("transfer")

local aiming = false
local crouch = false

local conn
conn = runService.Heartbeat:Connect(function()
	local mouseHit = mse.Hit

	local dist = (head.Position - cam.CFrame.p).Magnitude
	local diff = head.CFrame.Y - cam.CFrame.Y

	local ang = aiming and -math.rad(18) or 0

	nk.C0 = nk.C0:Lerp(nkc0 * CFrame.Angles(-math.atan(diff / dist), ang, 0), 0.2)
	-- repost if you hate manipulating r6 joints
	rs.C0 = rs.C0:Lerp(rsc0 * CFrame.Angles(0, 0, math.atan(diff / dist) * 0.9), 0.2)
	ls.C0 = ls.C0:Lerp(lsc0 * CFrame.Angles(0, 0, -math.atan(diff / dist) * 0.9), 0.2)

	--root.CFrame = CFrame.lookAt(root.Position, Vector3.new(mouseHit.X, root.Position.Y, mouseHit.Z))

	if crouch then
		humanoid.CameraOffset = humanoid.CameraOffset:Lerp(Vector3.new(0, -2, 0), 0.2)

		rj.C0 = rj.C0:Lerp(rjc0 * CFrame.new(0, 0, -1.7) * CFrame.Angles(math.rad(20), 0, 0), 0.2)
		rh.C0 = rh.C0:Lerp(rhc0 * CFrame.Angles(0, 0, -math.rad(30)) * CFrame.new(0.25, 1.7, 0), 0.2)
		lh.C0 = lh.C0:Lerp(lhc0 * CFrame.Angles(0, 0, math.rad(30)) * CFrame.new(-0.25, 1.7, 0), 0.2)
	else
		humanoid.CameraOffset = humanoid.CameraOffset:Lerp(Vector3.new(), 0.25)

		rj.C0 = rj.C0:Lerp(rjc0, 0.25)
		rh.C0 = rh.C0:Lerp(rhc0, 0.25)
		lh.C0 = lh.C0:Lerp(lhc0, 0.25)
	end

	transfer:FireServer(rj.C0, nk.C0, rs.C0, ls.C0, rh.C0, lh.C0)

	if humanoid:GetState() == Enum.HumanoidStateType.Dead then
		conn:Disconnect()
		return
	end
end)

UIS.InputBegan:Connect(function(inp, gp)
	if not gp then
		if inp.KeyCode == Enum.KeyCode.LeftControl and humanoid.Sit == false and humanoid.PlatformStand == false then
			crouch = true
			humanoid.WalkSpeed = 10
		end
	end
end)

UIS.InputEnded:Connect(function(inp, gp) -- i hate typing out UIS functions
	if not gp then
		if inp.KeyCode == Enum.KeyCode.LeftControl then
			crouch = false
			humanoid.WalkSpeed = 16
		end
	end
end)

script.aimEvent.Event:Connect(function(bool)
	if type(bool) == "boolean" then
		aiming = bool
	end
end)

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	if humanoid.Sit == true then
		crouch = false
		humanoid.WalkSpeed = 16
	end
end)
