--CODE RUN

local t = 0
timeNeeded = 0

UpdatePositions()

local AnimatingBind = game["Run Service"].Stepped:Connect(function(totalTime, step)
	
	t = t + (step * origin.Speed.Value)
	local alpha
	if timeNeeded == 0 then
		alpha = 1
	else
		alpha = math.min(1, t / math.max(.001,timeNeeded))
	end
	 
	
	for limb, position in pairs(desiredPositions) do
		limb.Transform = lastPositions[limb]:lerp(desiredPositions[limb], alpha)
		if alpha == 1 then
			lastPositions[limb] = desiredPositions[limb]
		end
	end
	
	if alpha == 1 then
		KFNumber = KFNumber + 1
		if KFNumber > maxKFNumber then
			if KeyframeAnimation.Loop then
				--ResetJoints()
				KFNumber = 1
			else
				ResetJoints()
				script:Destroy()
			end
		end
		
		UpdatePositions()
		t = 0
	end
	
end)