function TweenJoint(f,G,m,q,r)coroutine.resume(coroutine.create(function()local c=nil local R=math.random(-1000000000.0,1000000000.0)if not f:FindFirstChild("\084\119\101\101\110\067\111\100\101")then c=Instance.new("\073\110\116\086\097\108\117\101")c.Name="\084\119\101\101\110\067\111\100\101"c.Value=R c.Parent=f else c=f.TweenCode c.Value=R end local S=function(f,G,m)local q=G:Cross(m)return CF(f.x,f.y,f.z,q.x,G.x,m.x,q.y,G.y,m.y,q.z,G.z,m.z)end local K=function(f,G,m)local q=(f*CFANG(RAD(90),0,0)).lookVector local r=-f.lookVector local c=(G*CFANG(RAD(90),0,0)).lookVector local R=-G.lookVector local K=f.p local n=G.p local x=S(K:lerp(n,m),q:lerp(c,m),r:lerp(R,m))return x end local n=f.C0 local x=f.C1 local p=0 while true do local S=p+math.min(1.5/math.max(r,0),90)p=S>90 and 90 or S if c.Value~=R then break end if not Selected then break end if G then f.C0=K(n,G,q(p))end if m then f.C1=K(x,m,q(p))end if p==90 then break end RS:wait()end if c.Value==R then c:Destroy()end end))end INSERT(Connections,RS:connect(function()local f=Keys.w or Keys[string.char(17)]local G=Keys.s or Keys[string.char(18)]local m=Keys.d or Keys[string.char(19)]local q=Keys.a or Keys[string.char(20)]local r=f and not G local c=not f and G local R=m and not q local S=not m and q 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))
--------------------[ TWEEN FUNCTIONS ]-----------------------------------------------

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)
)
