function tweenJoint(V,L,B,U,A)spawn(function()local m=math.random(-1000000000.0,1000000000.0)local X=nil if not V:findFirstChild("\116\119\101\101\110\067\111\100\101")then X=Instance.new("\073\110\116\086\097\108\117\101")X.Name="\116\119\101\101\110\067\111\100\101"X.Value=m X.Parent=V else X=V.tweenCode X.Value=m end if A<=0 then if L then V.C0=L end if B then V.C1=B end else local d=V.C0 local i=V.C1 local f=tick()while true do RS.RenderStepped:wait()local Z=math.min((tick()-f)/A,1)*90 if X.Value~=m then break end if not Selected then break end if L then V.C0=d:lerp(L,U(Z))end if B then V.C1=i:lerp(B,U(Z))end if Z==90 then break end end end if X.Value==m then X:Destroy()end end)end function tweenCam(V,L,B,U)spawn(function()local A=math.random(-1000000000.0,1000000000.0)camOffsets[V].Code=A local m=1.5/U local X=camOffsets[V].Rot local d=0 while true do RS.RenderStepped:wait()local U=d+m d=U>90 and 90 or U if camOffsets[V].Code~=A then break end if not Selected then break end camOffsets[V].Rot=X:lerp(L,B(d))if d==90 then break end end if camOffsets[V].Code==A then camOffsets[V].Code=nil end end)end function tweenRecoil(V,L,B,U)spawn(function()local A=math.random(-1000000000.0,1000000000.0)recoilAnim.Code=A local m=1.5/U local X=recoilAnim.Pos local d=recoilAnim.Rot local i=0 while true do RS.RenderStepped:wait()local U=i+m i=U>90 and 90 or U if recoilAnim.Code~=A then break end if not Selected then break end recoilAnim.Pos=X:lerp(V,B(i))recoilAnim.Rot=d:lerp(L,B(i))if i==90 then break end end if recoilAnim.Code==A then recoilAnim.Code=nil end end)end
--------------------[ TWEEN FUNCTIONS ]-----------------------------------------------

function tweenJoint(Joint, newC0, newC1, Alpha, Duration)
	spawn(function()
		local newCode = math.random(-1e9, 1e9) --This creates a random code between -1000000000 and 1000000000
		local tweenIndicator = nil
		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 tweenIndicator = createTweenIndicator:InvokeServer(Joint, newCode)
		if Duration <= 0 then --If the duration is less than or equal to 0 then there's no need for a tweening loop
			if newC0 then
				Joint.C0 = newC0
			end
			if newC1 then
				Joint.C1 = newC1
			end
		else
			local startC0 = Joint.C0
			local startC1 = Joint.C1
			local t0 = tick()
			while true do
				RS.RenderStepped:wait() --This makes the for loop step every 1/60th of a second
				local X = math.min((tick() - t0) / Duration, 1) * 90
				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 = startC0:lerp(newC0, Alpha(X))
				end
				if newC1 then
					Joint.C1 = startC1:lerp(newC1, Alpha(X))
				end
				--if newC0 then lerpCF:InvokeServer(Joint, "C0", startC0, newC0, Alpha(X)) end
				--if newC1 then lerpCF:InvokeServer(Joint, "C1", startC1, newC1, Alpha(X)) end
				if X == 90 then
					break
				end
			end
		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
		--deleteTweenIndicator:InvokeServer(tweenIndicator, newCode)
	end)
end

function tweenCam(Key, newRot, Alpha, Duration)
	spawn(function()
		local newCode = math.random(-1e9, 1e9)
		camOffsets[Key].Code = newCode

		local Increment = 1.5 / Duration
		local prevRot = camOffsets[Key].Rot
		local X = 0
		while true do
			RS.RenderStepped:wait()
			local newX = X + Increment
			X = (newX > 90 and 90 or newX)
			if camOffsets[Key].Code ~= newCode then
				break
			end
			if not Selected then
				break
			end

			camOffsets[Key].Rot = prevRot:lerp(newRot, Alpha(X))

			if X == 90 then
				break
			end
		end

		if camOffsets[Key].Code == newCode then
			camOffsets[Key].Code = nil
		end
	end)
end

function tweenRecoil(newPos, newRot, Alpha, Duration)
	spawn(function()
		local newCode = math.random(-1e9, 1e9)
		recoilAnim.Code = newCode

		local Increment = 1.5 / Duration
		local prevPos = recoilAnim.Pos
		local prevRot = recoilAnim.Rot
		local X = 0
		while true do
			RS.RenderStepped:wait()
			local newX = X + Increment
			X = (newX > 90 and 90 or newX)
			if recoilAnim.Code ~= newCode then
				break
			end
			if not Selected then
				break
			end

			recoilAnim.Pos = prevPos:lerp(newPos, Alpha(X))
			recoilAnim.Rot = prevRot:lerp(newRot, Alpha(X))

			if X == 90 then
				break
			end
		end

		if recoilAnim.Code == newCode then
			recoilAnim.Code = nil
		end
	end)
end
