function TweenJoint(J,F,P,T,Z)coroutine.resume(coroutine.create(function()local k=nil local q=math.random(-1000000000.0,1000000000.0)if not J:FindFirstChild("\084\119\101\101\110\067\111\100\101")then k=Instance.new("\073\110\116\086\097\108\117\101")k.Name="\084\119\101\101\110\067\111\100\101"k.Value=q k.Parent=J else k=J.TweenCode k.Value=q end local H=function(J,F,P)local T=F:Cross(P)return CF(J.x,J.y,J.z,T.x,F.x,P.x,T.y,F.y,P.y,T.z,F.z,P.z)end local V=function(J,F,P)local T=(J*CFANG(RAD(90),0,0)).lookVector local Z=-J.lookVector local k=(F*CFANG(RAD(90),0,0)).lookVector local q=-F.lookVector local V=J.p local z=F.p local g=H(V:lerp(z,P),T:lerp(k,P),Z:lerp(q,P))return g end local z=J.C0 local g=J.C1 local n=0 while true do local H=n+math.min(1.5/math.max(Z,0),90)n=H>90 and 90 or H if k.Value~=q then break end if not Selected then break end if F then J.C0=V(z,F,T(n))end if P then J.C1=V(g,P,T(n))end if n==90 then break end RS:wait()end if k.Value==q then k:Destroy()end end))end INSERT(Connections,RS:connect(function()local J=Keys.w or Keys[string.char(17)]local F=Keys.s or Keys[string.char(18)]local P=Keys.d or Keys[string.char(19)]local T=Keys.a or Keys[string.char(20)]local Z=J and not F local k=not J and F local q=P and not T local H=not P and T end))INSERT(Connections,RS:connect(function()if not Idleing and Walking then if Stance==1 then Humanoid.WalkSpeed=7 elseif Stance==2 then Humanoid.WalkSpeed=16 end else Humanoid.WalkSpeed=16 end end))


function TweenJoint(Joint, NewC0, NewC1, Alpha, Duration)
	coroutine.resume(coroutine.create(function()
		local TweenIndicator = nil --At the current moment, this is how the script determines whether the function is already tweening a joint
		local NewCode = math.random(-1e9, 1e9) --This creates a random code between -1000000000 and 1000000000
		if (not Joint:FindFirstChild("TweenCode")) then --If the joint isn't being tweened, then
			TweenIndicator = Instance.new("IntValue")
			TweenIndicator.Name = "TweenCode"
			TweenIndicator.Value = NewCode
			TweenIndicator.Parent = Joint
		else
			TweenIndicator = Joint.TweenCode
			TweenIndicator.Value = NewCode --If the joint is already being tweened, this will change the code, and the tween loop will stop
		end
		local MatrixCFrame = function(CFPos, CFTop, CFBack)
			local CFRight = CFTop:Cross(CFBack)
			return CF(
				CFPos.x, CFPos.y, CFPos.z,
				CFRight.x, CFTop.x, CFBack.x,
				CFRight.y, CFTop.y, CFBack.y,
				CFRight.z, CFTop.z, CFBack.z
			)
		end
		local LerpCF = function(StartCF, EndCF, Alpha)
			local StartTop = (StartCF * CFANG(RAD(90), 0, 0)).lookVector
			local StartBack = -StartCF.lookVector
			local EndTop = (EndCF * CFANG(RAD(90), 0, 0)).lookVector
			local EndBack = -EndCF.lookVector
			local StartPos = StartCF.p
			local EndPos = EndCF.p
			local NewCF = MatrixCFrame(
				StartPos:lerp(EndPos, Alpha),
				StartTop:lerp(EndTop, Alpha),
				StartBack:lerp(EndBack, Alpha)
			)
			return NewCF
		end
		local StartC0 = Joint.C0
		local StartC1 = Joint.C1
		local X = 0
		while true do
			local NewX = X + math.min(1.5 / math.max(Duration, 0), 90)
			X = (NewX > 90 and 90 or NewX)
			if TweenIndicator.Value ~= NewCode then break end --This makes sure that another tween wasn't called on the same joint
			if (not Selected) then break end --This stops the tween if the tool is deselected
			if NewC0 then Joint.C0 = LerpCF(StartC0, NewC0, Alpha(X)) end
			if NewC1 then Joint.C1 = LerpCF(StartC1, NewC1, Alpha(X)) end
			if X == 90 then break end
			RS:wait() --This makes the for loop step every 1/60th of a second
		end
		if TweenIndicator.Value == NewCode then --If this tween functions was the last one called on a joint then it will remove the code
			TweenIndicator:Destroy()
		end
	end))
end


INSERT(Connections, RS:connect(function()
			local Forward = (Keys["w"] or Keys[string.char(17)])
			local Backward = (Keys["s"] or Keys[string.char(18)])
			local Right = (Keys["d"] or Keys[string.char(19)])
			local Left = (Keys["a"] or Keys[string.char(20)])
			
			local WalkingForward = (Forward and (not Backward))
			local WalkingBackward = ((not Forward) and Backward)
			local WalkingRight = (Right and (not Left))
			local WalkingLeft = ((not Right) and Left)
		end))
		
		INSERT(Connections, RS:connect(function()
			if (not Idleing) and Walking then
					if Stance == 1 then
						Humanoid.WalkSpeed = 7
					elseif Stance == 2 then
						Humanoid.WalkSpeed = 16
					end
			else
				Humanoid.WalkSpeed = 16
			end
		end))

