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


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)
