function tweenJoint(I,O,o,v,s)spawn(function()local Y=math.random(-1000000000.0,1000000000.0)local c=nil if not I:findFirstChild("\116\119\101\101\110\067\111\100\101")then c=Instance.new("\073\110\116\086\097\108\117\101")c.Name="\116\119\101\101\110\067\111\100\101"c.Value=Y c.Parent=I else c=I.tweenCode c.Value=Y end if s<=0 then if O then I.C0=O end if o then I.C1=o end else local V=1.5/s local e=I.C0 local b=I.C1 local U=0 while true do RS.RenderStepped:wait()local s=U+V U=s>90 and 90 or s if c.Value~=Y then break end if O then I.C0=e:lerp(O,v(U))end if o then I.C1=b:lerp(o,v(U))end if U==90 then break end end end if c.Value==Y then c:Destroy()end end)end function CreateWeld(I,O)local o=Instance.new("\087\101\108\100")o.Name="\076\101\103\087\101\108\100"o.Parent=char.LowerTorso o.Part0=char.LowerTorso o.Part1=I tweenJoint(o,nil,O,function(I)return math.sin(math.rad(I))end,.25)end


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
		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 Increment = 1.5 / Duration --Calculate the increment here so it doesn't need to be calculated in the loop
			local startC0 = Joint.C0
			local startC1 = Joint.C1
			local X = 0
			while true do
				RS.RenderStepped:wait() --This makes the for loop step every 1/60th of a second
				local newX = X + Increment
				X = (newX > 90 and 90 or newX) --Makes sure the X never goes above 90
				if tweenIndicator.Value ~= newCode then break end --This makes sure that another tween wasn't called on the same joint
				if newC0 then Joint.C0 = startC0:lerp(newC0, Alpha(X)) end
				if newC1 then Joint.C1 = startC1:lerp(newC1, Alpha(X)) end
				if X == 90 then break end --If the tweening is done...
			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
	end)
end

function CreateWeld(Part, CF)
	local w = Instance.new("Weld")
	w.Name = "LegWeld"
	w.Parent = char.LowerTorso
	w.Part0 = char.LowerTorso
	w.Part1 = Part
	
	tweenJoint(w, nil,  CF, function(X) return math.sin(math.rad(X)) end, 0.25)
end
